-
-
Save wasauce/b8b2607c7023c906558af55d75faedb7 to your computer and use it in GitHub Desktop.
mitm - Load Hacker News from local file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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