From 8cf0cca70240b232b15c8b972c2d8fa32d73f964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhan=20Kavrako=C4=9Flu?= Date: Sat, 25 May 2024 16:13:17 +0200 Subject: [PATCH] Fix slowdown when sending large data over HTTP/2 (#6873) (#6875) * Do not mutate data when splitting into chunks (#6873) * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 ++ mitmproxy/proxy/layers/http/_http_h2.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) 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.