Skip to content

Phase 2.1: incremental HTTP request parser - #16

Merged
MukhammadIbrokhimov merged 9 commits into
mainfrom
feature/phase-2-1-request-parser
Jun 18, 2026
Merged

Phase 2.1: incremental HTTP request parser#16
MukhammadIbrokhimov merged 9 commits into
mainfrom
feature/phase-2-1-request-parser

Conversation

@MukhammadIbrokhimov

Copy link
Copy Markdown
Owner

Summary

  • Request class: line-oriented incremental state machine (S_REQUEST_LINE → S_HEADERS → S_COMPLETE / S_ERROR)
  • Errors stored as HTTP status codes (400/414/431/505), never thrown — phase 4.5 consumes these for free
  • Pipelining-ready: parseFromBuffer returns bytes-consumed so 2.5 can re-feed leftovers to a fresh Request
  • Security hardening: bare-CR rejection, CTL/NUL rejection in URI + header names/values, mandatory & non-empty Host on HTTP/1.1
  • Size caps (8 KB request line → 414, 8 KB header line → 431, 100 headers → 431) enforced against the raw buffer, so a no-newline flood trips the cap instead of growing memory (subject no-crash rule)
  • Framework-free unit suite, 88 checks, incl. an exhaustive split-point sweep (every fragmentation boundary + byte-by-byte, CRLF and bare-LF); make unit
  • -MMD header-dependency tracking added so header edits trigger rebuilds

Scope

Standalone parser only. No server wiring (task 2.5), no body parsing (task 3.1) — both have clean hooks left in place. docs/superpowers/ specs/plans are local-only (gitignored).

Test plan

  • make unit → 88 passed, 0 failed
  • make re → full server builds warning-free under -Wall -Wextra -Werror -std=c++98
  • make fclean leaves no artifacts; leaks reports 0 leaked bytes

Header names/values now get the same CTL-byte hardening the URI got in
Phase 2.1: names reject uc<0x20 and 0x7F (NUL truncates CGI env names
in 3.3), values reject the same except HTAB (legal inside field-content
per RFC 7230). Empty Host is also rejected -- nginx does the same, and
2.5's vhost matcher shouldn't need a fallback for a zero-length host.
8 new checks; total suite 61 passed, 0 failed.
Copilot AI review requested due to automatic review settings June 13, 2026 18:45

Copilot AI 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.

Pull request overview

This PR adds an incremental, line-oriented HTTP/1.x request parser (Request) designed to safely handle arbitrary TCP fragmentation and request pipelining, and introduces a framework-free unit test suite plus Makefile support to build/run it.

Changes:

  • Implement Request as an incremental state machine with size caps, strict request-line/header validation, and error reporting via HTTP status codes (no exceptions).
  • Add a standalone unit test binary (make unit) with broad coverage, including exhaustive fragmentation split-point sweeps.
  • Update build system for header dependency tracking (-MMD -MP) and ignore the unit test binary in git.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unit/test_request.cpp Adds framework-free unit tests validating incremental parsing behavior, limits, and hardening cases.
src/http/request.cpp Implements the incremental request parser state machine, validation rules, caps, and consumed-byte accounting.
src/http/http.cpp Removes now-unneeded content (per diff, file is effectively emptied/removed).
Makefile Adds dependency tracking and a unit target to build/run the new unit test binary.
kanban.md Marks 2.1 complete and updates the parseFromBuffer contract description to match the implementation.
includes/http.hpp Introduces the Request API and parsing state machine definition in the public header.
.gitignore Ignores the unit test binary output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MukhammadIbrokhimov
MukhammadIbrokhimov merged commit 38aa8c4 into main Jun 18, 2026
3 checks passed
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