mitmproxy/examples/addons/http-stream-modify.py
Maximilian Hils 08895e9ba6 restructure examples
- restructure examples (fix #4031)
 - remove example dependencies from setup.py,
   we do not need special dependencies for our supported addons.
 - unify how we generate docs from code
 - improve example docs
2020-06-23 16:00:14 +02:00

22 lines
662 B
Python

"""
Modify a streamed response.
Generally speaking, we recommend *not* to stream messages you need to modify.
Modifying streamed responses is tricky and brittle:
- If the transfer encoding isn't chunked, you cannot simply change the content length.
- If you want to replace all occurrences of "foobar", make sure to catch the cases
where one chunk ends with [...]foo" and the next starts with "bar[...].
"""
def modify(chunks):
"""
chunks is a generator that can be used to iterate over all chunks.
"""
for chunk in chunks:
yield chunk.replace("foo", "bar")
def responseheaders(flow):
flow.response.stream = modify