From a3fd70f2405d4b7582441d8d598fd6e78b3dd702 Mon Sep 17 00:00:00 2001 From: sanlengjingvv Date: Sun, 14 Mar 2021 18:42:29 +0800 Subject: [PATCH] fix lint error --- mitmproxy/proxy/layers/http/__init__.py | 1 + mitmproxy/proxy/layers/http/_hooks.py | 2 ++ mitmproxy/proxy/layers/http/_http2.py | 6 ++---- test/mitmproxy/proxy/layers/http/test_http2.py | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mitmproxy/proxy/layers/http/__init__.py b/mitmproxy/proxy/layers/http/__init__.py index cae90c0d0..985544ff1 100644 --- a/mitmproxy/proxy/layers/http/__init__.py +++ b/mitmproxy/proxy/layers/http/__init__.py @@ -302,6 +302,7 @@ class HttpStream(layer.Layer): if isinstance(event, ResponseData): self.response_body_buf += event.data elif isinstance(event, ResponseTrailers): + assert self.flow.response self.flow.response.trailers = event.trailers yield HttpResponseTrailersHook(self.flow) elif isinstance(event, ResponseEndOfMessage): diff --git a/mitmproxy/proxy/layers/http/_hooks.py b/mitmproxy/proxy/layers/http/_hooks.py index cf33626df..f353a254e 100644 --- a/mitmproxy/proxy/layers/http/_hooks.py +++ b/mitmproxy/proxy/layers/http/_hooks.py @@ -44,6 +44,7 @@ class HttpResponseHook(commands.StartHook): name = "response" flow: http.HTTPFlow + @dataclass class HttpResponseTrailersHook(commands.StartHook): """ @@ -52,6 +53,7 @@ class HttpResponseTrailersHook(commands.StartHook): name = "responsetrailers" flow: http.HTTPFlow + @dataclass class HttpErrorHook(commands.StartHook): """ diff --git a/mitmproxy/proxy/layers/http/_http2.py b/mitmproxy/proxy/layers/http/_http2.py index efd752207..0d1923eb8 100644 --- a/mitmproxy/proxy/layers/http/_http2.py +++ b/mitmproxy/proxy/layers/http/_http2.py @@ -99,10 +99,7 @@ class Http2Connection(HttpConnection): self.h2_conn.send_data(event.stream_id, event.data) elif isinstance(event, ResponseTrailers): if self.is_open_for_us(event.stream_id): - trailers = [ - *event.trailers.fields - ] - r = event.trailers.fields + trailers = [*event.trailers.fields] self.h2_conn.send_headers(event.stream_id, trailers, event.end_stream) elif isinstance(event, self.SendEndOfMessage): if self.is_open_for_us(event.stream_id): @@ -458,6 +455,7 @@ class Http2Client(Http2Connection): elif isinstance(event, h2.events.TrailersReceived): pseudo_trailers, trailers = split_pseudo_headers(event.headers) yield ReceiveHttp(ResponseTrailers(event.stream_id, trailers, bool(event.stream_ended))) + return False elif isinstance(event, h2.events.RequestReceived): yield from self.protocol_error(f"HTTP/2 protocol error: received request from server") return True diff --git a/test/mitmproxy/proxy/layers/http/test_http2.py b/test/mitmproxy/proxy/layers/http/test_http2.py index 95dfc0ba3..94c3c4808 100644 --- a/test/mitmproxy/proxy/layers/http/test_http2.py +++ b/test/mitmproxy/proxy/layers/http/test_http2.py @@ -35,6 +35,7 @@ example_response_trailers = ( (b'my-trailer-b', b'0') ) + def decode_frames(data: bytes) -> List[hyperframe.frame.Frame]: # swallow preamble if data.startswith(b"PRI * HTTP/2.0"):