diff --git a/mitmproxy/test/tutils.py b/mitmproxy/test/tutils.py index 5b2bfe353..79751060e 100644 --- a/mitmproxy/test/tutils.py +++ b/mitmproxy/test/tutils.py @@ -46,7 +46,7 @@ def tresp(**kwargs) -> http.Response: reason=b"OK", headers=http.Headers(((b"header-response", b"svalue"), (b"content-length", b"7"))), content=b"message", - trailers=http.Headers(((b"trailer-response", b"svalue"), (b"trailer", b"this trailer-1"))), + trailers=None, timestamp_start=946681202, timestamp_end=946681203, ) diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index d0d9d4e9b..aeed8b114 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -6,6 +6,7 @@ import pytest from mitmproxy import exceptions from mitmproxy.addons import dumper +from mitmproxy.net.http import Headers from mitmproxy.test import taddons from mitmproxy.test import tflow from mitmproxy.test import tutils @@ -128,15 +129,17 @@ def test_echo_body(): f = tflow.tflow(client_conn=True, server_conn=True, resp=True) f.response.headers["content-type"] = "text/html" + f.response.headers["transfer-encoding"] = "chunked" + f.response.headers["trailer"] = "my-little-trailer" f.response.content = b"foo bar voing\n" * 100 - f.response.trailers["trailer-2"] = "this is trailer 2" + f.response.trailers = Headers([(b"my-little-trailer", b"foobar-trailer")]) d._echo_headers(f.response.headers) d._echo_message(f.response, f) d._echo_headers(f.response.trailers) t = sio.getvalue() assert "content-type" in t assert "cut off" in t - assert "trailer-2" in t + assert "foobar-trailer" in t def test_echo_request_line(): diff --git a/test/mitmproxy/net/http/http1/test_assemble.py b/test/mitmproxy/net/http/http1/test_assemble.py index 4fea192fc..ab3dac04c 100644 --- a/test/mitmproxy/net/http/http1/test_assemble.py +++ b/test/mitmproxy/net/http/http1/test_assemble.py @@ -40,6 +40,22 @@ def test_assemble_response(): b"message" ) + resp = tresp() + resp.headers["transfer-encoding"] = "chunked" + resp.headers["trailer"] = "my-little-trailer" + resp.trailers = Headers([(b"my-little-trailer", b"foobar")]) + assert assemble_response(resp) == ( + b"HTTP/1.1 200 OK\r\n" + b"header-response: svalue\r\n" + b"content-length: 7\r\n" + b"transfer-encoding: chunked\r\n" + b"trailer: my-little-trailer\r\n" + b"\r\n7\r\n" + b"message" + b"\r\n0\r\n" + b"my-little-trailer: foobar\r\n\r\n" + ) + with pytest.raises(exceptions.HttpException): assemble_response(tresp(content=None))