Repository navigation
fix(http1): drop trailers when the peer speaks HTTP/1 instead of crashing - #8628
Open
ToniAdreal wants to merge 1 commit into
Open
ToniAdreal wants to merge 1 commit into
ToniAdreal wants to merge 1 commit into
Conversation
…hing Fixes mitmproxy#8573. HttpLayer forwards request/response trailers to the peer's protocol layer whenever flow.request.trailers / flow.response.trailers is set, but Http1Client.send / Http1Server.send had no branch for trailer events and fell through to raise AssertionError. An h2/h3 peer sending legal trailers therefore crashed the stream whenever the other side was HTTP/1, and the upstream connection was left in read_body state (RequestEndOfMessage never dispatched). This drops RequestTrailers in Http1Client.send and ResponseTrailers in Http1Server.send. Trailers are optional metadata, and HTTP/1.1 only supports them as a chunked trailer section, which we do not emit, so dropping is the correct behaviour for content-length bodies. The RequestEndOfMessage / ResponseEndOfMessage that follows still runs mark_done, so the connection stays reusable. Signed-off-by: ToniAdreal <[email protected]>
ToniAdreal
force-pushed
the
fix-8573-h1-trailers
branch
from
November 19, 2026 14:03
4437f54 to
15a8a51
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.
Fixes #8573.
HttpLayerforwards request/response trailers to the peer's protocol layer wheneverflow.request.trailers/flow.response.trailersis set, butHttp1Client.send/Http1Server.sendhad no branch for trailer events and fell through toraise AssertionError. An h2/h3 peer sending legal trailers therefore crashed the stream whenever the other side was HTTP/1, and the upstream connection was left inread_bodystate (RequestEndOfMessagenever dispatched).This drops
RequestTrailersinHttp1Client.sendandResponseTrailersinHttp1Server.send. Trailers are optional metadata, and HTTP/1.1 only supports them as a chunked trailer section, which we do not emit, so dropping is the correct behaviour for content-length bodies. TheRequestEndOfMessage/ResponseEndOfMessagethat follows still runsmark_done, so the connection stays reusable.Verified locally (main @ f7701d5):
AssertionError: Playbook mismatch!, the trailer event falls through toraise AssertionError).test/mitmproxy/proxy/layers/http/test_http_version_interop.py(test_h2_request_trailers_to_h1,test_h1_response_trailers_from_h2) pass, and the existingtest_http_version_interop.py(4 passed) andtest_http2.py/test_http1.py(59 passed) still pass.ruff checkandruff format --checkpass on the touched files.Not done here (possible follow-up): emitting trailers as a chunked trailer section when the body was sent chunked, and replacing the blanket
raise AssertionErrorinsend()with a logged protocol error.