Repository navigation
Mark HTTP/2 flows imported from HAR files as HTTP/2 - #8583
Open
JayOfTheKeyboard wants to merge 1 commit into
Open
JayOfTheKeyboard wants to merge 1 commit into
JayOfTheKeyboard wants to merge 1 commit into
Conversation
The HAR importer stored HTTP/2 versions as "HTTP/2", but mitmproxy uses "HTTP/2.0" everywhere else, so is_http2 was False for every imported HTTP/2 flow. mitmproxy's own HAR export writes "HTTP/2.0", which matched no case at all and came back as HTTP/1.1. With is_http2 False, client replay of an imported HTTP/2 flow over an HTTP/1 connection skipped the HTTP/2 -> HTTP/1 conversion and sent "GET /path HTTP/2" as the request line, which servers reject.
JayOfTheKeyboard
force-pushed
the
har-import-http2-version
branch
from
November 9, 2026 06:50
c8d3d70 to
4b8ddf1
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The HAR importer stores HTTP/2 as
"HTTP/2", butMessage.is_http2and the HTTP/2 layer use"HTTP/2.0". So HTTP/2 flows loaded from a browser HAR (Chrome writeshttp/2.0, Safari writesHTTP/2) haveis_http2 == False. A HAR exported by mitmproxy itself writes"HTTP/2.0", which matches none of the cases and comes back as HTTP/1.1.It shows up in client replay. With
is_http2False, the HTTP/1 layer skips its HTTP/2 to HTTP/1 conversion and puts the version straight into the request line. With a HAR entry that has"httpVersion": "http/2.0"and a plainpython -m http.serveras the target:The server receives
GET /hello HTTP/2. With this change the request goes out asGET /hello HTTP/1.1and gets a 200.This maps
http/2.0,HTTP/2andHTTP/2.0toHTTP/2.0for both the request and the response. The expectedhttp_versionin five HAR fixtures changes to match (head-content-length.harwas exported withHTTP/2.0, so it used to load as HTTP/1.1).Chrome HARs also list the HTTP/2 pseudo-headers (
:authority,:method, ...) as ordinary headers, and the importer keeps them, so replaying a Chrome entry still fails, on main and on this branch alike, withReceived invalid header name: b':authority'. I left that for a separate PR, along with Chrome'sh3version string, which still imports as HTTP/1.1. I can send either.#8535 edits the same
matchblocks for HTTP/1.0. The two changes don't depend on each other, and whichever lands second needs a one-line rebase.Testing:
test_http2_versionchecksis_http2on both sides for all three spellings. It fails on main withassert False where False = Request(GET address:22/path).is_http2.tox -e py,lint,mypy,filename_matchingpasses on main and on this branch (2026 vs 2029 passed, the 3 new tests), andindividual_coverageis ok formitmproxy/io/har.py.Checklist