aboutsummaryrefslogtreecommitdiffstats
path: root/doc-src/features/responsestreaming.html
blob: 6511e913c81de6962bc2e9c078d58cbec948d65b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
By using mitmproxy's streaming feature, response contents can be passed to the client incrementally before they have been fully received by the proxy.
This is especially useful for large binary files such as videos, where buffering the whole file slows down the client's browser.

By default, mitmproxy will read the entire response, perform any indicated
manipulations on it and then send the (possibly modified) response to
the client. In some cases this is undesirable and you may wish to "stream"
the reponse back to the client. When streaming is enabled, the response is
not buffered on the proxy but directly sent back to the client instead.

<h2>On the command-line</h2>

Streaming can be enabled on the command line for all response bodies exceeding a certain size.  The SIZE argument understands
k/m/g suffixes, e.g. 3m for 3 megabytes.

<table class="table">
    <tbody>
    <tr>
        <th width="20%">command-line</th>
        <td>
            --stream SIZE
        </td>
    </tr>
    </tbody>
</table>


<h2>Caveats</h2>

When response streaming is enabled, <strong>streamed response contents will not be
    recorded or preserved in any way.</strong>

When response streaming is enabled, the response body cannot be modified.

<h2>Customizing Response Streaming</h2>

You can also use an <a href="@!urlTo("scripting/inlinescripts.html")!@">inline script</a> to customize exactly
which responses are streamed.

Responses that should be tagged for streaming by setting their respective .stream attribute to True:

$!example("examples/stream.py")!$

<h2>Implementation Details</h2>

When response streaming is enabled, portions of the code which would have otherwise performed changes
on the response body will see an empty response body instead (<code>libmproxy.protocol.http.CONTENT_MISSING</code>). Any modifications will be ignored.

Streamed responses are usually sent in chunks of 4096 bytes. If the response is sent with a <code>Transfer-Encoding:
    chunked</code> header, the response will be streamed one chunk at a time.

<h2>Modifying streamed data</h2>
If the <code>.stream</code> attribute is callable, .stream will work as a hook in chunk data processing.

$!example("examples/stream_modify.py")!$

### See Also

- [Ignore Domains](@!urlTo("passthrough.html")!@)