diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f662f2deb..093fa94f11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ ([#6821](https://github.com/mitmproxy/mitmproxy/pull/6821), @Prinzhorn) * Fix a bug where client replay would not work with proxyauth. ([#6866](https://github.com/mitmproxy/mitmproxy/pull/6866), @mhils) +* Fix slowdown when sending large data over HTTP/2 + ([#6875](https://github.com/mitmproxy/mitmproxy/pull/6875), @aib) ## 17 April 2024: mitmproxy 10.3.0 diff --git a/mitmproxy/proxy/layers/http/_http_h2.py b/mitmproxy/proxy/layers/http/_http_h2.py index 60a88f6002..75d20dcbfe 100644 --- a/mitmproxy/proxy/layers/http/_http_h2.py +++ b/mitmproxy/proxy/layers/http/_http_h2.py @@ -68,12 +68,12 @@ def send_data( frame_size = len(data) assert pad_length is None - while frame_size > self.max_outbound_frame_size: - chunk_data = data[: self.max_outbound_frame_size] - self.send_data(stream_id, chunk_data, end_stream=False) + if frame_size > self.max_outbound_frame_size: + for start in range(0, frame_size, self.max_outbound_frame_size): + chunk = data[start : start + self.max_outbound_frame_size] + self.send_data(stream_id, chunk, end_stream=False) - data = data[self.max_outbound_frame_size :] - frame_size -= len(chunk_data) + return if self.stream_buffers.get(stream_id, None): # We already have some data buffered, let's append.