Phase 6: HTTP/1.1 Parser#
Implement HTTP/1.1 message parsing in the net crate (RFC 7230, 7231).
Requirements#
- Request serialization:
- Request line:
METHOD SP Request-URI SP HTTP/1.1 CRLF - Headers:
field-name: field-value CRLF - Required headers: Host, User-Agent, Accept, Connection
- Optional: Content-Length, Content-Type for request bodies
- Request line:
- Response parsing:
- Status line:
HTTP/1.1 SP status-code SP reason-phrase CRLF - Header parsing: case-insensitive field names, multi-line values
HttpResponse { status_code, headers, body }type
- Status line:
- Transfer-Encoding: chunked (RFC 7230 ยง4.1):
- Parse chunk-size (hex) CRLF chunk-data CRLF
- Handle last-chunk (size 0) and optional trailers
- Dechunk response body transparently
- Content-Length handling: read exact number of body bytes
- Header types:
Headerscollection with case-insensitive lookup - Content-Type parsing: extract MIME type and charset parameter
Dependencies#
- None (pure parsing, no I/O)
Acceptance Criteria#
- Serialize HTTP/1.1 GET and POST requests
- Parse HTTP/1.1 response status lines
- Parse headers with case-insensitive lookup
- Handle Content-Length bodies
- Handle chunked Transfer-Encoding
- Handle responses with no body (204, 304)
- Parse Content-Type with charset
- Edge cases: empty body, zero Content-Length, missing Content-Length with chunked
- Comprehensive tests (30+ tests)
-
cargo clippyandcargo fmtclean