Skip to content

Send headers of later requests after 100 Continue - #2399

Merged
hyperxpro merged 1 commit into
AsyncHttpClient:mainfrom
mkurz:fix/continue-headers-on-redirect
Nov 21, 2026
Merged

hyperxpro merged 1 commit into
AsyncHttpClient:mainfrom
mkurz:fix/continue-headers-on-redirect

Conversation

@mkurz

@mkurz mkurz commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • After a 100 Continue, every later HTTP/1.1 attempt on the same NettyResponseFuture was sent without its headers: a redirect, a 401 or 407 retry, a retry after the connection closed, and a ResponseFilter or IOExceptionFilter replay.
  • A request without a body or with an in-memory body (a byte array, a String, a ByteBuf, form parameters) is a single message, so nothing reached the server and the request waited for its timeout. Any other body was written without a request line, and Netty's encoder rejected it, for example with EncoderException: unexpected message type: BodyFileRegion.
  • Continue100Interceptor sets headersAlreadyWrittenOnContinue so that writeRequest sends the deferred body without the headers, which already went out. Nothing reset the flag. Until 664a50b (January 2014, first released in 2.0.0-alpha1), writeRequest reset it each time it read it (getAndSetWriteHeaders(true)).

Change

  • NettyResponseFuture.setNettyRequest clears the flag, as it already re-arms tunnelEstablished. Every request sent on an existing future goes through it, from NettyRequestSender.newNettyRequestAndResponseFuture. The deferred body is written by a second writeRequest call for the same request, without a new one, so it still goes out without the headers.
  • Clearing the flag in writeRequest, as before 2014, would not be enough. A 100 also sets it when nothing was deferred. That is the case for an in-memory body, which HTTP/1.1 sends with the headers even with Expect: 100-continue. Since fix(netty): fail fast when InputStream body cannot be reset #2312, no writeRequest follows such a 100, so the flag would stay set until the next request, and that request would skip its headers.
  • HTTP/2 does not read the flag.
  • Tests:
    • RedirectBodyTest: after a 100, a 307 keeps the method, the headers and the body, with a byte array and with a ByteArrayBodyGenerator; a 303 reaches the target as a GET; a multipart body survives a 307. A ResponseFilter records the statuses, and each test checks that a 100 came before the redirect.
    • The RedirectBodyTest handler now sends the 100 itself with Jetty's HttpChannel.continue100(0). Jetty skips it when the content came with the headers, which is what an in-memory body does. Without Expect: 100-continue the call does nothing, and the existing tests of the class pass unchanged.
    • Expect100ContinueTest: a Basic auth retry after a 100, and a ResponseFilter replay after a 100 and a 503, both with a file body. The server reads the body, which sends the 100, then answers 401 or 503.

Notes

  • Unchanged here:
    • A 303 that switches to GET keeps the Expect: 100-continue header, although RFC 9110 section 10.1.1 says a client must not send it without content.
    • A request that follows a 100 sends its body right away, even when it carries Expect: 100-continue, as dontWriteBodyBecauseExpectContinue is only set when the future is created. RFC 9110 allows that. The target in the redirect tests answers it with another 100, which does not defer anything.
  • Found by reading the code, not tested: the 407 retry takes the same path as the 401 retry. A future that got its 100 over HTTP/2 and then follows a redirect to an HTTP/1.1 origin would also have sent the redirect without headers; the same change covers it.

AI disclosure

Claude Code on behalf of Matthias Kurz. The commit includes Co-Authored-By per AGENTS.md.

Test plan

  • The 6 new tests fail on main and pass with this PR. On main, the byte array 307 and the 303 time out, as nothing reaches the target. The generator 307 fails with unexpected message type: AdvancedLeakAwareByteBuf, the multipart 307 with unexpected message type: BodyFileRegion, and the 401 retry and the filter replay with unexpected message type: DefaultFileRegion. The other 51 tests of the two classes pass on both.
  • With writeRequest writing the headers even after a 100, the existing Expect100Continue, authorizedNonPreemptiveRealmWorksWithExpectContinue and deferredInputStream307KeepsBody fail, and so do the new tests with a deferred body. The skip for the deferred body is still needed, and tests cover it.
  • Throwaway tests, not included, with a deferred body after a 100: a retry after the server closed the connection, and an IOExceptionFilter replay after that close. Both fail on main with an EncoderException and pass with this PR.
  • 40 test classes on 100-continue, redirects, retries, replays and auth, including RedirectBodyTest, Expect100ContinueTest, Continue100InterceptorTest, MultipartBasicAuthTest, Http2ConformanceRegressionTest, RetryRequestTest, FilterTest, CrossHostReplayTest, BasicAuthTest, DigestAuthTest, NtlmTest and ProxyTest: 319 tests, 0 failures, 2 skipped (@Disabled in AuthTimeoutTest).
  • RedirectBodyTest, Expect100ContinueTest, Continue100InterceptorTest and MultipartBasicAuthTest: 63 tests, 0 failures, on JDK 11, 17, 21 and 25.
  • ./mvnw -B -ntp -Dgpg.skip=true clean verify on JDK 11: 2,214 tests, 0 failures, 0 errors, 22 skipped; Revapi passed. Docker was not running, so 11 of the skipped tests are the Testcontainers proxy tests, which skip themselves. No test-skipping flags were used.

A 100 Continue sets headersAlreadyWrittenOnContinue on the
NettyResponseFuture, so that writeRequest sends the deferred body
without the headers, which went out before. Nothing reset the flag, so
every later HTTP/1.1 attempt on the same future was sent without its
headers too: a redirect, a 401 or 407 retry, a retry after the
connection closed, and a ResponseFilter or IOExceptionFilter replay. A
request without a body or with an in-memory body is a single message,
so nothing at all was written and the request timed out. Other bodies
were written on their own, and the HTTP/1.1 encoder rejected them, for
example with "unexpected message type: BodyFileRegion".

Until 664a50b in 2014, writeRequest reset the flag each time it read
it.

The flag is now cleared in setNettyRequest, like tunnelEstablished.
Every request sent on an existing future goes through it. The deferred
body is written by calling writeRequest again for the same request,
without a new one, so it still skips the headers. Clearing the flag
where it is read, as before 2014, would not be enough: a 100 also sets
it when nothing was deferred, for example for an in-memory body, which
HTTP/1.1 sends with the headers. Nothing reads the flag then until the
next request, which would skip its headers. HTTP/2 does not read the
flag.

Claude Code on behalf of Matthias Kurz

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hyperxpro
hyperxpro merged commit 3d0a347 into AsyncHttpClient:main Nov 21, 2026
13 checks passed
@mkurz
mkurz deleted the fix/continue-headers-on-redirect branch November 21, 2026 19:12
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