Skip to content

Fix/http11 conformance#24

Merged
jjmrocha merged 3 commits into
mainfrom
fix/http11-conformance
Jun 8, 2026
Merged

Fix/http11 conformance#24
jjmrocha merged 3 commits into
mainfrom
fix/http11-conformance

Conversation

@jjmrocha

@jjmrocha jjmrocha commented Jun 8, 2026

Copy link
Copy Markdown
Owner

No description provided.

jjmrocha added 3 commits June 8, 2026 23:47
Introduce HttpConnectionReader to buffer per-connection input (supports pipelining and prevents read-ahead loss) and provide byte-accurate line/body reads (ISO-8859-1 for lines, raw bytes for bodies). Update RequestParser to use the new reader, correctly handle Content-Length as octet counts, read chunked bodies into byte buffers, and avoid character-based over-reading. Change RequestProcessor.process to accept HttpConnectionReader and OutputStream and adapt IOServer to create/pass the reader per client socket. Enhance ResponseWriter to emit Content-Length: 0 for bodyless responses when a body is allowed to ensure definite framing on keep-alive connections. Add and update tests (HttpConnectionReaderTest, RequestParserTest, RequestProcessorTest, IOServerTest, ResponseWriterTest) and adjust mocks accordingly. Also add /.serena to .gitignore. Note: this includes an API change to RequestProcessor.process (signature change).
Add stricter protocol checks and defensive parsing to RequestParser and update tests accordingly. Changes include: enforce Host header for HTTP/1.1 and reject duplicate Host headers; treat presence of both Content-Length and Transfer-Encoding as a protocol error; validate Content-Length is numeric and non-negative; parse chunk-size lines while ignoring extensions and validate chunk sizes; enforce an aggregate cap on chunked bodies to prevent unbounded growth; correct keep-alive semantics to depend on HTTP version and explicit Connection header. Tests were adjusted (some header-limit tests use HTTP/1.0) and several new tests added for invalid Content-Length, invalid chunk sizes, chunk extensions, aggregate chunk size limit, Host header requirements, and ensuring RequestProcessor returns 400 for malformed Content-Length.
Add strict per-line framing and limits to HttpConnectionReader (CRLF required, 8KB max line length) to prevent request-smuggling and unbounded memory growth; invalid terminators or overlong lines now throw ProtocolException. Remove redundant header-size check from RequestParser since line limits are enforced by the reader. Refactor RequestProcessor to extract handler invocation and ensure Connection: close is honored even when handlers throw (500 responses also close). Update ResponseWriter to avoid duplicating the Date header when already set and to write headers/body using UTF-8. Add and adjust unit tests to cover bare-LF rejection, overlong lines, connection-close propagation on errors, non-duplicated Date header, and UTF-8 body writing.
@jjmrocha jjmrocha merged commit d936b6d into main Jun 8, 2026
1 check failed
@jjmrocha jjmrocha deleted the fix/http11-conformance branch June 8, 2026 23:16
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.

1 participant