Skip to content

Instantly share code, notes, and snippets.

@jokester
Created November 7, 2018 07:03
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 jokester/0a1cc9656e42120429089207b4f33846 to your computer and use it in GitHub Desktop.
Save jokester/0a1cc9656e42120429089207b4f33846 to your computer and use it in GitHub Desktop.
mitmproxy: delay transfer of css response body
# usage: mitmproxy -s THIS_FILE.py
# add a delay before starting streaming response body to client
from time import sleep
from urllib.parse import urlparse
def delay_before_streaming_response(flow):
url = urlparse(flow.request.url)
if url.path.lower().endswith('.css'):
return 2
return 0
def responseheaders(flow):
def modify(chunks):
sleep(delay_before_streaming_response(flow))
# continue to stream original response
yield from chunks
flow.response.stream = modify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment