reject 1xx responses with a body in prepare_payload#3104
Open
sahvx655-wq wants to merge 1 commit into
Open
Conversation
ashtum
approved these changes
Jul 1, 2026
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.
prepare_payload on a response is meant to reject a body for the status codes RFC 7230 says cannot carry one, but the 1xx branch never fires. At message.hpp:393 status_class(this->result()) is a functional-style cast rather than a call to to_status_class, so it reinterprets the numeric status (e.g. 100) as a status_class value and compares it against status_class::informational, whose underlying value is 1. The test is false for every real 1xx code, so a 100/101/102/103 response built with a non-empty body sails through and even gets a synthesised Content-Length. 204 and 304 still throw because they are checked explicitly by value; only the whole 1xx class was broken.
The sibling need_eof a few lines up at message.hpp:345 does the same classification correctly with to_status_class, which is what tipped me off. Switching line 393 to to_status_class makes the 1xx case throw invalid_argument like 204/304, so the library no longer emits a 1xx response with a body and a Content-Length that RFC 7230 3.3.2 forbids and that an intermediary can read as message framing. Valid responses are untouched; the case added to testPreparePayload fails on the four 1xx codes before the change and passes after.