engineering notes
Parser behavior
The parser is strict on purpose: it waits for CRLF CRLF, validates the request line, normalizes headers, and refuses to guess when the body is incomplete.
Header boundary detection
src/parseStreamRequest.ts treats the incoming buffer as raw bytes first. The parser searches for CRLF CRLF, which is the only signal that the header section is complete. Until that marker exists, the parser returns incomplete and leaves the buffer untouched.
That behavior matters in real TCP traffic because a request can arrive in multiple packets. The parser is written to tolerate fragmentation instead of assuming line-oriented input.
Request line validation
Once the header boundary exists, the first line is passed into parseRequestLine(). The method must be an uppercase token, the request target must begin with a slash, and the version must be exactly HTTP/1.1.
This is intentionally narrower than a fully general HTTP implementation. The goal is a dependable learning server, not a compatibility layer for every possible client variation.
Header normalization and body completion
Header parsing lives in src/parseHeader.ts. Field names are lowercased, invalid characters are rejected, and whitespace in the wrong place fails immediately. That gives the rest of the application a stable header shape.
Content-Length is the decisive body rule. If it exists, it must parse as a non-negative integer. The parser then checks whether the buffer contains enough body bytes. If not, it returns incomplete rather than producing a half-valid request object.