fix http trailer tests

This commit is contained in:
Thomas Kriechbaumer 2020-10-31 11:42:26 +01:00
parent 14b42101d6
commit a415c218ea
3 changed files with 22 additions and 3 deletions

View File

@ -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,
)

View File

@ -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():

View File

@ -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))