Skip to content

Instantly share code, notes, and snippets.

@grunka
Created July 2, 2018 08:55
Show Gist options
  • Save grunka/c2dcaae203cf187b6b1ede1ffc07d073 to your computer and use it in GitHub Desktop.
Save grunka/c2dcaae203cf187b6b1ede1ffc07d073 to your computer and use it in GitHub Desktop.
mitmproxy script for replacing a specific url with the content from a local file
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
if "example.com/path/file.html" in flow.request.pretty_url:
with open('replacement.html', 'r') as myfile:
html = myfile.read().replace('\n', '')
flow.response = http.HTTPResponse.make(
200, # status code
html, # content
{"Content-Type": "text/html"}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment