Skip to content

Instantly share code, notes, and snippets.

@jlongman
Created June 15, 2017 18:28
Show Gist options
  • Save jlongman/b8290a85a0dcf4bff227c11d2c5bb034 to your computer and use it in GitHub Desktop.
Save jlongman/b8290a85a0dcf4bff227c11d2c5bb034 to your computer and use it in GitHub Desktop.
mitmproxy mitmdump script that injects 404s for streaming chunks
#!/usr/bin/env python
from mitmproxy import ctx
# an intermittent 404 for .ts files - HLS m3u8 streaming chunks
def start():
return Foo()
class Foo:
MUCHO = 0
def response(self, flow):
flow.response.headers["x-myproxy"] = "proxy"
if not flow.request.path.endswith('.ts'):
#and not flow.request.path.endswith('.m3u8'):
return
ctx.log.info("MUCHO {} - {}".format(self.MUCHO, flow.request.path))
self.MUCHO += 1
if not (self.MUCHO % 20 == 0):
# only every 20 or so return 404 - so it's intermittent.
return
if flow.response.status_code != 404:
headers = flow.response.headers
del headers["access-control-allow-origin"]
flow.response.status_code = 404
flow.response.reason = "We're in charge"
else:
flow.response.headers["x-myproxy"] = "404 not ours"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment