Repository navigation
answer Expect: 100-continue once per request in ParseHttpMessage - #3704
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The duplicate-response fix is covered by per-request Expect handling state and a fragmented-body regression test, with no active review issues remaining.
No open issues 🎉
What changed in this PR
This pull request fixes duplicate HTTP/1.1 100 Continue responses when a request body arrives across multiple reads. It tracks per-request Expect handling and adds regression coverage for fragmented request bodies.
Changes:
- Track whether the
Expectheader has already been processed. - Emit
100 Continueonly once per request. - Add a test verifying a single interim response followed by
200 OK.
| File | Description |
|---|---|
test/brpc_http_rpc_protocol_unittest.cpp |
Adds fragmented-body regression coverage for duplicate interim responses. |
src/brpc/policy/http_rpc_protocol.h |
Adds per-request state tracking for handled Expect headers. |
src/brpc/policy/http_rpc_protocol.cpp |
Prevents repeated 100 Continue responses during incremental parsing. |
Review effort: Lite
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
ParseHttpMessage()answersExpect: 100-continuewhenever it is called on a request whose headers are complete but whose body is not, and nothing records that the expectation was already answered.InputMessenger::OnNewMessages()calls the parser again after everyread(), so a request whose body arrives in several reads is answered with oneHTTP/1.1 100 Continueper read instead of once per request. With the new test on master, a body sent in four pieces drew four extra interim responses in front of the200 OK. RFC 9110 section 10.1.1 has the server send the100 (Continue)right after the header section and lets it omit the response once some of the content has arrived; it never calls for one per read.The interim response is written with
ignore_eovercrowded, so it is not subject tosocket_max_unwritten_bytes. A client that sends the headers, then trickles the body one byte per segment and never reads, makes the server queue one interim response per segment with no cap. This happens in the parser, before any service orServerOptions.authis involved. Well-behaved clients see it too: a large upload withExpect: 100-continuegets a stream of interim responses, one per server read.What is changed and the side effects?
Changed:
HttpContextrecords thatParseHttpMessage()has dealt with theExpectheader of the request, so the interim response is written once. The header itself stays on the request, so services still see it (the existingHttpTest.http_expectrelies on that).HttpTest.http_expect_answered_onceintest/brpc_http_rpc_protocol_unittest.cpp: headers first, then the body in pieces with a pause between them. It fails on master (a second100 Continuearrives before the200 OK) and passes with the change.Side effects:
Performance effects: none on the normal path; one header lookup less per read of a partially received body.
Breaking backward compatibility: no. A request still gets exactly one
100 Continue; only the repeats go away.Check List:
Tests run (CMake Debug build on Linux):
brpc_http_rpc_protocol_unittest(66 tests),brpc_http_message_unittest,brpc_server_unittestandbrpc_builtin_service_unittest, all passing.