Skip to content

Instantly share code, notes, and snippets.

@wasauce
Created November 29, 2020 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasauce/b8b2607c7023c906558af55d75faedb7 to your computer and use it in GitHub Desktop.
Save wasauce/b8b2607c7023c906558af55d75faedb7 to your computer and use it in GitHub Desktop.
mitm - Load Hacker News from local file
"""
Load Hacker News from local file.
Local file is updated via a different process (curl-ing the site)
Other process is run every 60 seconds.
"""
from mitmproxy import http
from mitmproxy import ctx
def request(flow: http.HTTPFlow) -> None:
flow.request.query["mitmproxy"] = "rocks"
if 'news.ycombinator.com' in flow.request.pretty_url:
name = '/Users/wferrell/Desktop/ycombinator.html'
with open(name) as html_file:
data = html_file.read()
flow.response = http.HTTPResponse.make(
200, # (optional) status code
data, # (optional) content
{"Content-Type": "text/html"} # (optional) headers
)
def response(flow: http.HTTPFlow) -> None:
ctx.log.info("Flow matches filter:")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment