fix lint error

This commit is contained in:
sanlengjingvv 2021-03-14 18:42:29 +08:00
parent 76d7ee3a2f
commit a3fd70f240
4 changed files with 6 additions and 4 deletions

View File

@ -302,6 +302,7 @@ class HttpStream(layer.Layer):
if isinstance(event, ResponseData): if isinstance(event, ResponseData):
self.response_body_buf += event.data self.response_body_buf += event.data
elif isinstance(event, ResponseTrailers): elif isinstance(event, ResponseTrailers):
assert self.flow.response
self.flow.response.trailers = event.trailers self.flow.response.trailers = event.trailers
yield HttpResponseTrailersHook(self.flow) yield HttpResponseTrailersHook(self.flow)
elif isinstance(event, ResponseEndOfMessage): elif isinstance(event, ResponseEndOfMessage):

View File

@ -44,6 +44,7 @@ class HttpResponseHook(commands.StartHook):
name = "response" name = "response"
flow: http.HTTPFlow flow: http.HTTPFlow
@dataclass @dataclass
class HttpResponseTrailersHook(commands.StartHook): class HttpResponseTrailersHook(commands.StartHook):
""" """
@ -52,6 +53,7 @@ class HttpResponseTrailersHook(commands.StartHook):
name = "responsetrailers" name = "responsetrailers"
flow: http.HTTPFlow flow: http.HTTPFlow
@dataclass @dataclass
class HttpErrorHook(commands.StartHook): class HttpErrorHook(commands.StartHook):
""" """

View File

@ -99,10 +99,7 @@ class Http2Connection(HttpConnection):
self.h2_conn.send_data(event.stream_id, event.data) self.h2_conn.send_data(event.stream_id, event.data)
elif isinstance(event, ResponseTrailers): elif isinstance(event, ResponseTrailers):
if self.is_open_for_us(event.stream_id): if self.is_open_for_us(event.stream_id):
trailers = [ trailers = [*event.trailers.fields]
*event.trailers.fields
]
r = event.trailers.fields
self.h2_conn.send_headers(event.stream_id, trailers, event.end_stream) self.h2_conn.send_headers(event.stream_id, trailers, event.end_stream)
elif isinstance(event, self.SendEndOfMessage): elif isinstance(event, self.SendEndOfMessage):
if self.is_open_for_us(event.stream_id): if self.is_open_for_us(event.stream_id):
@ -458,6 +455,7 @@ class Http2Client(Http2Connection):
elif isinstance(event, h2.events.TrailersReceived): elif isinstance(event, h2.events.TrailersReceived):
pseudo_trailers, trailers = split_pseudo_headers(event.headers) pseudo_trailers, trailers = split_pseudo_headers(event.headers)
yield ReceiveHttp(ResponseTrailers(event.stream_id, trailers, bool(event.stream_ended))) yield ReceiveHttp(ResponseTrailers(event.stream_id, trailers, bool(event.stream_ended)))
return False
elif isinstance(event, h2.events.RequestReceived): elif isinstance(event, h2.events.RequestReceived):
yield from self.protocol_error(f"HTTP/2 protocol error: received request from server") yield from self.protocol_error(f"HTTP/2 protocol error: received request from server")
return True return True

View File

@ -35,6 +35,7 @@ example_response_trailers = (
(b'my-trailer-b', b'0') (b'my-trailer-b', b'0')
) )
def decode_frames(data: bytes) -> List[hyperframe.frame.Frame]: def decode_frames(data: bytes) -> List[hyperframe.frame.Frame]:
# swallow preamble # swallow preamble
if data.startswith(b"PRI * HTTP/2.0"): if data.startswith(b"PRI * HTTP/2.0"):