warn users if sse flows are received without streaming, refs #4469 (#5249)

This commit is contained in:
Maximilian Hils 2022-04-06 12:51:58 +02:00 committed by GitHub
parent 0454f63e98
commit 02d2b6d310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 1 deletions

View File

@ -6,6 +6,8 @@
([#5227](https://github.com/mitmproxy/mitmproxy/issues/5227), @mhils) ([#5227](https://github.com/mitmproxy/mitmproxy/issues/5227), @mhils)
* Console Performance Improvements * Console Performance Improvements
([#3427](https://github.com/mitmproxy/mitmproxy/issues/3427), @BkPHcgQL3V) ([#3427](https://github.com/mitmproxy/mitmproxy/issues/3427), @BkPHcgQL3V)
* Warn users if server side event responses are received without streaming.
([#4469](https://github.com/mitmproxy/mitmproxy/issues/4469), @mhils)
* Add flatpak support to the browser addon * Add flatpak support to the browser addon
([#5200](https://github.com/mitmproxy/mitmproxy/issues/5200), @pauloromeira) ([#5200](https://github.com/mitmproxy/mitmproxy/issues/5200), @pauloromeira)
* Add example addon to dump contents to files based on a filter expression * Add example addon to dump contents to files based on a filter expression

View File

@ -358,7 +358,8 @@ By default, mitmproxy will read an entire request/response, perform any
indicated manipulations on it, and then send the message on to the other party. indicated manipulations on it, and then send the message on to the other party.
This can be problematic when downloading or uploading large files. When This can be problematic when downloading or uploading large files. When
streaming is enabled, message bodies are not buffered on the proxy but instead streaming is enabled, message bodies are not buffered on the proxy but instead
sent directly to the server/client. HTTP headers are still fully buffered before sent directly to the server/client. This currently means that the message body
will not be accessible within mitmproxy. HTTP headers are still fully buffered before
being sent. being sent.
Request/response streaming is enabled by specifying a size cutoff in the Request/response streaming is enabled by specifying a size cutoff in the

View File

@ -0,0 +1,19 @@
from mitmproxy import ctx, http
class ServerSideEvents:
"""
Server-Side Events are currently swallowed if there's no streaming,
see https://github.com/mitmproxy/mitmproxy/issues/4469.
Until this bug is fixed, this addon warns the user about this.
"""
def response(self, flow: http.HTTPFlow):
assert flow.response
is_sse = flow.response.headers.get("content-type", "").startswith("text/event-stream")
if is_sse and not flow.response.stream:
ctx.log.warn(
"mitmproxy currently does not support server side events. As a workaround, you can enable response "
"streaming for such flows: https://github.com/mitmproxy/mitmproxy/issues/4469"
)

View File

@ -0,0 +1,12 @@
from mitmproxy.addons.server_side_events import ServerSideEvents
from mitmproxy.test import taddons
from mitmproxy.test.tflow import tflow
async def test_simple():
s = ServerSideEvents()
with taddons.context() as tctx:
f = tflow(resp=True)
f.response.headers["content-type"] = "text/event-stream"
s.response(f)
await tctx.master.await_log("mitmproxy currently does not support server side events.")

View File

@ -39,6 +39,7 @@ def test_format_keyvals():
def test_truncated_text(): def test_truncated_text():
urwid.set_encoding("utf8")
half_width_text = common.TruncatedText("Half-width", []) half_width_text = common.TruncatedText("Half-width", [])
full_width_text = common.TruncatedText("", []) full_width_text = common.TruncatedText("", [])
assert half_width_text.render((10,)) assert half_width_text.render((10,))