Skip to content

close connection after http/1.0 request with transfer-encoding - #751

Open
rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:http10-request-te-close
Open

rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:http10-request-te-close

Conversation

@rootvector2

Copy link
Copy Markdown

DefaultConnectionReuseStrategy.keepAlive treats an HTTP/1.0 response with Transfer-Encoding as faulty framing, but not an HTTP/1.0 request. The server still decodes POST / HTTP/1.0 with Transfer-Encoding: chunked and Connection: keep-alive as chunked, keeps the connection open, and parses the bytes after the body as the next request. An HTTP/1.0 intermediary doesn't know Transfer-Encoding and frames that request differently. I found this by reading the reuse strategy against RFC 9112 section 6.1 and confirmed it on the classic server with a raw socket: before the fix a pipelined GET after such a request reaches the handler, and after it the connection closes once the first response is sent.

The fix adds the request-side rule from RFC 9112 section 6.1, next to the existing check for a request with both Content-Length and Transfer-Encoding. It's a single header lookup per exchange and applies only to HTTP/1.0 requests, so HTTP/1.1 traffic is unaffected. testRequestHTTP10TransferEncodingPresent covers it.

@@ -85,6 +85,12 @@ public boolean keepAlive(
if (request.containsHeader(HttpHeaders.CONTENT_LENGTH) && request.containsHeader(HttpHeaders.TRANSFER_ENCODING)) {

@ok2c ok2c Nov 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rootvector2 Let's optimize it a bit and execute CONTENT_LENGTH and TRANSFER_ENCODING checks only once

final boolean contentLenPresent = request.containsHeader(HttpHeaders.CONTENT_LENGTH);
final boolean transferEncodingPresent = request.containsHeader(HttpHeaders.TRANSFER_ENCODING);
if (contentLenPresent && transferEncodingPresent) {
...

// Consider framing of a HTTP/1.0 request message with Transfer-Encoding header faulty
final ProtocolVersion requestVersion = request.getVersion();
if (requestVersion != null && requestVersion.lessEquals(HttpVersion.HTTP_1_0)
&& request.containsHeader(HttpHeaders.TRANSFER_ENCODING)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rootvector2 Let's avoid repeating the same check.

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