Added support to echo http trailers in dumper addon

This commit is contained in:
Shiva 2020-10-15 13:48:39 +05:30 committed by Thomas Kriechbaumer
parent 1fa4ec7419
commit f4b9930b05
4 changed files with 22 additions and 4 deletions

View File

@ -12,6 +12,7 @@ from mitmproxy import exceptions
from mitmproxy import flowfilter from mitmproxy import flowfilter
from mitmproxy.utils import human from mitmproxy.utils import human
from mitmproxy.utils import strutils from mitmproxy.utils import strutils
from mitmproxy.net import http
def indent(n: int, text: str) -> str: def indent(n: int, text: str) -> str:
@ -225,6 +226,8 @@ class Dumper:
self._echo_response_line(f) self._echo_response_line(f)
if ctx.options.flow_detail >= 2: if ctx.options.flow_detail >= 2:
self._echo_headers(f.response.headers) self._echo_headers(f.response.headers)
if f.response.trailers is not None and isinstance(f.response.trailers, http.Headers):
self._echo_headers(f.response.trailers)
if ctx.options.flow_detail >= 3: if ctx.options.flow_detail >= 3:
self._echo_message(f.response, f) self._echo_message(f.response, f)

View File

@ -9,9 +9,10 @@ protobuf messages sent as WebSocket frames.
Thus, the View API is very minimalistic. The only arguments are `data` and Thus, the View API is very minimalistic. The only arguments are `data` and
`**metadata`, where `data` is the actual content (as bytes). The contents on `**metadata`, where `data` is the actual content (as bytes). The contents on
metadata depend on the protocol in use. For HTTP, the message headers are metadata depend on the protocol in use. For HTTP, the message headers and
passed as the ``headers`` keyword argument. For HTTP requests, the query message trailers are passed as the ``headers`` and ``trailers`` keyword
parameters are passed as the ``query`` keyword argument. argument. For HTTP requests, the query parameters are passed as the ``query``
keyword argument.
""" """
import traceback import traceback
from typing import Dict, Optional # noqa from typing import Dict, Optional # noqa
@ -103,6 +104,7 @@ def get_message_content_view(viewname, message, flow):
metadata["query"] = message.query metadata["query"] = message.query
if isinstance(message, http.Message): if isinstance(message, http.Message):
metadata["headers"] = message.headers metadata["headers"] = message.headers
metadata["trailers"] = message.trailers
metadata["message"] = message metadata["message"] = message
metadata["flow"] = flow metadata["flow"] = flow

View File

@ -46,7 +46,7 @@ def tresp(**kwargs) -> http.Response:
reason=b"OK", reason=b"OK",
headers=http.Headers(((b"header-response", b"svalue"), (b"content-length", b"7"))), headers=http.Headers(((b"header-response", b"svalue"), (b"content-length", b"7"))),
content=b"message", content=b"message",
trailers=None, trailers=http.Headers(((b"trailer-response", b"svalue"), (b"trailer", b"this trailer-1"))),
timestamp_start=946681202, timestamp_start=946681202,
timestamp_end=946681203, timestamp_end=946681203,
) )

View File

@ -124,6 +124,19 @@ def test_echo_body():
d._echo_message(f.response, f) d._echo_message(f.response, f)
t = sio.getvalue() t = sio.getvalue()
assert "cut off" in t assert "cut off" in t
sio.truncate(0)
f = tflow.tflow(client_conn=True, server_conn=True, resp=True)
f.response.headers["content-type"] = "text/html"
f.response.content = b"foo bar voing\n" * 100
f.response.trailers["trailer-2"] = "this is trailer 2"
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
def test_echo_request_line(): def test_echo_request_line():