Skip to content

reject 1xx responses with a body in prepare_payload#3104

Open
sahvx655-wq wants to merge 1 commit into
boostorg:developfrom
sahvx655-wq:prepare-payload-1xx-body
Open

reject 1xx responses with a body in prepare_payload#3104
sahvx655-wq wants to merge 1 commit into
boostorg:developfrom
sahvx655-wq:prepare-payload-1xx-body

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants