Repository navigation
feat: add incremental HTTP/1.1 response parser - #13
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb508a8b12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const char* const code_last = code_first + 3; | ||
| const auto parsed_code = std::from_chars(code_first, code_last, status_code, 10); | ||
| if (parsed_code.ec != std::errc{} || parsed_code.ptr != code_last | ||
| || status_code < 100 || status_code > 999) { |
There was a problem hiding this comment.
When a peer sends a status line such as HTTP/1.1 600 Weird, this upper bound accepts it and exposes an invalid status as a successful response. HTTP status codes outside 100–599 are invalid, so this should return InvalidStatusLine rather than proceeding with body framing.
Useful? React with 👍 / 👎.
| if (status_line.size() > code_begin + 3) { | ||
| if (status_line[code_begin + 3] != ' ') { |
There was a problem hiding this comment.
Require the separator after the status code
When the status line ends immediately after the code, for example HTTP/1.1 204\r\n, this conditional skips the separator check and accepts the response. The HTTP/1.1 status-line grammar requires a space after the three-digit code even when the reason phrase is empty, so this malformed input should produce InvalidStatusLine.
Useful? React with 👍 / 👎.
Summary
Adds the first incremental HTTP/1.1 response parser on top of the existing
Headers,Response, and transport-oriented architecture.Added
include/cpp_request/response.hppResponsevalue typestring_viewaccesssrc/http/response_parser.hpp/.cpp1xxhandling before the final responseContent-LengthframingConnection: closereuse semanticsContent-Lengthbody for a following responseTransfer-Encoding+Content-LengthNeedsChunkedDecoderhandoff for validTransfer-Encoding: chunked101connections are never marked reusable as HTTP connections100 ContinueParser model
The parser owns only bytes that must survive across
read_some()calls. It does not assume TCP packet boundaries match HTTP lines or body boundaries. For length-delimited responses it consumes exactly the declared body length and leaves any following bytes pending, which is required for safe keep-alive reuse.Chunked boundary
This PR intentionally does not decode chunked bodies yet. When a valid chunked response head is recognized, the parser returns
ResponseParseProgress::NeedsChunkedDecoderand leaves all body bytes untouched inpending_bytes(). The next PR can attach the chunk decoder to this explicit state without redesigning status/header parsing.Scope
This PR does not execute socket reads itself, decode chunked bodies, implement redirects, or add the public
Clientrequest orchestration path.