Add RFC 7230 validation for chunked transfer-encoding

Validate after fast parser returns:
- Reject chunked with HTTP/1.0
- Reject chunked + Content-Length conflict
This commit is contained in:
Benoit Chesneau 2026-03-22 00:18:25 +01:00
parent 0ca0d0cb02
commit 87bfb7d190

View File

@ -219,6 +219,16 @@ class HttpParser:
pr.content_length = req.content_length if req.content_length >= 0 else 0
pr.chunked = req.has_chunked
# Validate Transfer-Encoding per RFC 7230
if pr.chunked:
# Chunked requires HTTP/1.1+
if req.minor_version < 1:
raise InvalidHeader("TRANSFER-ENCODING")
# Chunked with Content-Length is invalid
if req.content_length >= 0:
raise InvalidHeader("CONTENT-LENGTH")
pr.content_length = -1
# connection_close: -1 = not set, 0 = keep-alive, 1 = close
if req.connection_close == 1:
pr.must_close = True