aboutsummaryrefslogtreecommitdiffstats
path: root/examples/stream_modify.py
blob: a28d95c7ac7da065bbf610407a1b331b52f700d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""
This inline script won't work with --stream SIZE command line option.

That's because flow.response.stream will be overwritten to True if the
command line option exists.
"""

def modify(chunks):
    """
    chunks is a generator that can be used to iterate over all chunks.
    Each chunk is a (prefix, content, suffix) tuple. 
    For example, in the case of chunked transfer encoding: ("3\r\n","foo","\r\n")
    """
    for prefix, content, suffix in chunks:
        yield prefix, content.replace("foo","bar"), suffix

def responseheaders(ctx, flow):
    flow.response.stream = modify
    flow.response.stream_large_bodies = 1024 # = 1KB