diff options
| author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2016-07-03 13:25:29 +0200 |
|---|---|---|
| committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2016-07-05 20:14:28 +0200 |
| commit | 47db3469590e7987898ea753215982bde09d4568 (patch) | |
| tree | f1276c69b887979075b2ae672336774db90a7b6a | |
| parent | aa1b20318216f066c0acb22b429b74b5ed1ce111 (diff) | |
| download | mitmproxy-47db3469590e7987898ea753215982bde09d4568.tar.gz mitmproxy-47db3469590e7987898ea753215982bde09d4568.tar.bz2 mitmproxy-47db3469590e7987898ea753215982bde09d4568.zip | |
improve end_stream handling
To replicate requests as close as possible frame-by-frame.
This fixes an issue with broken HTTP/2 implemenation by Akamai and
Twitter, which raise an error if we send an empty DataFrame only to
indicate END_STREAM.
| -rw-r--r-- | mitmproxy/protocol/http2.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/mitmproxy/protocol/http2.py b/mitmproxy/protocol/http2.py index d848affa..f398630d 100644 --- a/mitmproxy/protocol/http2.py +++ b/mitmproxy/protocol/http2.py @@ -140,6 +140,7 @@ class Http2Layer(base.Layer): headers = netlib.http.Headers([[k, v] for k, v in event.headers]) self.streams[eid] = Http2SingleStreamLayer(self, eid, headers) self.streams[eid].timestamp_start = time.time() + self.streams[eid].no_body = (event.stream_ended is not None) if event.priority_updated is not None: self.streams[eid].priority_weight = event.priority_updated.weight self.streams[eid].priority_depends_on = event.priority_updated.depends_on @@ -307,6 +308,8 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread) self.response_queued_data_length = 0 self.response_data_finished = threading.Event() + self.no_body = False + self.priority_weight = None self.priority_depends_on = None self.priority_exclusive = None @@ -409,6 +412,7 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread) self.is_zombie, self.server_stream_id, headers, + end_stream=self.no_body, priority_weight=self.priority_weight, priority_depends_on=self.priority_depends_on, priority_exclusive=self.priority_exclusive, @@ -418,11 +422,13 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread) finally: self.server_conn.h2.lock.release() - self.server_conn.h2.safe_send_body( - self.is_zombie, - self.server_stream_id, - message.body - ) + if not self.no_body: + self.server_conn.h2.safe_send_body( + self.is_zombie, + self.server_stream_id, + message.body + ) + if self.zombie: # pragma: no cover raise exceptions.Http2ProtocolException("Zombie Stream") |
