From 6d8a315c5d67283e6917762f2f1a93e9617fa136 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 24 Nov 2020 14:48:22 +0100 Subject: [PATCH] assume keep-alive for HTTP/2 --- mitmproxy/net/http/http1/read.py | 5 ++++- test/mitmproxy/net/http/http1/test_read.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mitmproxy/net/http/http1/read.py b/mitmproxy/net/http/http1/read.py index 53c4d723f..42b9fe530 100644 --- a/mitmproxy/net/http/http1/read.py +++ b/mitmproxy/net/http/http1/read.py @@ -167,7 +167,10 @@ def connection_close(http_version, headers): elif "keep-alive" in tokens: return False - return http_version != "HTTP/1.1" and http_version != b"HTTP/1.1" + return http_version not in ( + "HTTP/1.1", b"HTTP/1.1", + "HTTP/2.0", b"HTTP/2.0", + ) def expected_http_body_size( diff --git a/test/mitmproxy/net/http/http1/test_read.py b/test/mitmproxy/net/http/http1/test_read.py index 9746c1e1d..be2197a85 100644 --- a/test/mitmproxy/net/http/http1/test_read.py +++ b/test/mitmproxy/net/http/http1/test_read.py @@ -146,6 +146,7 @@ def test_connection_close(): headers = Headers() assert connection_close(b"HTTP/1.0", headers) assert not connection_close(b"HTTP/1.1", headers) + assert not connection_close(b"HTTP/2.0", headers) headers["connection"] = "keep-alive" assert not connection_close(b"HTTP/1.1", headers)