mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 19:08:44 +00:00
08895e9ba6
- 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
22 lines
662 B
Python
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
|