2020-07-03 10:49:31 +00:00
|
|
|
"""
|
|
|
|
This script simply prints all received HTTP Trailers.
|
|
|
|
|
|
|
|
HTTP requests and responses can container trailing headers which are sent after
|
|
|
|
the body is fully transmitted. Such trailers need to be announced in the initial
|
|
|
|
headers by name, so the receiving endpoint can wait and read them after the
|
|
|
|
body.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from mitmproxy import http
|
|
|
|
from mitmproxy.net.http import Headers
|
|
|
|
|
2020-07-05 23:01:48 +00:00
|
|
|
|
2020-07-03 10:49:31 +00:00
|
|
|
def request(flow: http.HTTPFlow):
|
|
|
|
if flow.request.trailers:
|
|
|
|
print("HTTP Trailers detected! Request contains:", flow.request.trailers)
|
|
|
|
|
2020-07-05 23:01:48 +00:00
|
|
|
|
2020-07-03 10:49:31 +00:00
|
|
|
def response(flow: http.HTTPFlow):
|
|
|
|
if flow.response.trailers:
|
|
|
|
print("HTTP Trailers detected! Response contains:", flow.response.trailers)
|
|
|
|
|
|
|
|
if flow.request.path == "/inject_trailers":
|
|
|
|
flow.response.headers["trailer"] = "x-my-injected-trailer-header"
|
|
|
|
flow.response.trailers = Headers([
|
|
|
|
(b"x-my-injected-trailer-header", b"foobar")
|
|
|
|
])
|
|
|
|
print("Injected a new trailer...", flow.response.headers["trailer"])
|