Skip to content

Add a standalone HTTP/1.1 request-head parser - #3112

Open
HarshPopat23 wants to merge 5 commits into
sourcemeta:mainfrom
HarshPopat23:http-request-head-parser
Open

HarshPopat23 wants to merge 5 commits into
sourcemeta:mainfrom
HarshPopat23:http-request-head-parser

Conversation

@HarshPopat23

@HarshPopat23 HarshPopat23 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds http_parse_request_head to Core as a standalone API for parsing the HTTP/1.1 request line and headers directly from a byte buffer.

  • Distinguishes complete, incomplete, and malformed input.
  • Reports the exact number of bytes consumed through the terminating blank line, leaving any body bytes untouched.
  • Preserves header order and repeated field names, and trims optional whitespace around field values.

This first PR focuses on request-head syntax. Request-target semantics, Host validation, and body framing are follow-up work.

Verification

  • All 13 new parser tests passed on Linux with GCC 14.2 in a Release build. They cover complete input, truncated input, malformed syntax, and the exact boundary before body bytes.
  • The existing HTTP and AWS Signature V4 suites passed.
  • Formatting and diff checks passed.

View guided diff

Signed-off-by: HarshPopat23 <musichk61@gmail.com>
@augmentcode

augmentcode Bot commented Nov 20, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Adds http_parse_request_head to parse HTTP/1.1 request heads from byte buffers.

  • Introduces HTTPRequestHead and HTTPRequestHeadStatus.
  • Distinguishes complete, incomplete, and malformed input.
  • Returns borrowed views for the method, target, and fields.
  • Requires CRLF endings and single spaces in the request line.
  • Validates method and field-name tokens.
  • Checks visible ASCII targets and permitted field-value octets.
  • Trims optional whitespace while preserving field order and duplicates.
  • Reports bytes consumed through the blank line, leaving body bytes untouched.
  • Defers request-target semantics, Host validation, and body framing.
  • Exposes the API through http.h and registers the implementation.
  • Adds 13 tests covering complete, truncated, malformed, and body-boundary input.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

View guided diff | Re-trigger cubic

Signed-off-by: HarshPopat23 <musichk61@gmail.com>
Signed-off-by: HarshPopat23 <musichk61@gmail.com>
Signed-off-by: HarshPopat23 <musichk61@gmail.com>
@HarshPopat23

Copy link
Copy Markdown
Contributor Author

PTAL : @jviotti

/// The request target as sent, or an empty view unless complete.
std::string_view target{};
/// Field names and values in wire order, including repeated names.
std::vector<std::pair<std::string_view, std::string_view>> fields{};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be called "headers"? In general, can you go through the HTTP RFCs and make sure we match their terminology exactly?

/// Callers can append input and retry from the beginning when incomplete.
/// Keep the input alive and unmodified while using the returned views.
SOURCEMETA_CORE_HTTP_EXPORT
auto http_parse_request_head(std::string_view input) -> HTTPRequestHead;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word _head here is confusing. Maybe _envelope or see what the RFCs actually use if any

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any official suite somewhere we could use too? There must be some re-usable HTTP parsing test suites somewhere right?

/// Callers can append input and retry from the beginning when incomplete.
/// Keep the input alive and unmodified while using the returned views.
SOURCEMETA_CORE_HTTP_EXPORT
auto http_parse_request_head(std::string_view input) -> HTTPRequestHead;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto http_parse_request_head(std::string_view input) -> HTTPRequestHead;
auto http_parse_request_head(const std::string_view input) -> HTTPRequestHead;

just as a convention nit pick

Signed-off-by: HarshPopat23 <musichk61@gmail.com>
@HarshPopat23

Copy link
Copy Markdown
Contributor Author

@jviotti

  1. Renamed the parser to http_parse_request_line_and_headers and the result member from fields to headers. RFC 9112 calls the collection headers or the header section and calls the preceding line the request line.
  2. Added const to the parameter in the public declaration, matching the implementation.
  3. The HTTP Working Group’s testing resources list no official conformance suite. I adapted two cases from llhttp’s pinned request fixtures to cover optional whitespace and an empty header section.

This branch has not been deployed

No deployments
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