Repository navigation
Conversation
When a retry, redirect or replay is routed through another proxy than
the attempt before, a Proxy-Authorization header the request carries
was meant for the previous proxy, so the request is copied without it.
That copy went through Request.toBuilder(), which always uses the
fixing URI encoder. A request built with URL encoding disabled was
therefore sent to the new proxy encoded again:
GET http://host/a|b?q={x} became GET http://host/a%7Cb?q=%7Bx%7D.
Copy a DefaultRequest with the raw encoder instead, as AsyncHttpClient#2393 does when
it adds a Range header. The URI of a built request is already encoded,
so the raw encoder returns it unchanged. Subclasses and other Request
implementations still go through toBuilder(), as they may override
what it copies.
Claude Code on behalf of Matthias Kurz
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test for a selector that alternates between two proxies only counted CONNECTs. A tunnel entry that followed the selector to the other proxy would still write the request on the channel it holds, so it opens no second tunnel and the test passed, while the channel is then pooled under the other proxy's key. Send a second request through the proxy that opened the tunnel: it has to take that tunnel from the pool. Claude Code on behalf of Matthias Kurz Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 407 answered on a kept-alive connection sets connectAllowed, so that its retry sends a CONNECT on the connection it holds. Only a tunnel that opens clears the flag again, so after a 407 on a plain http request it stays set for the rest of the exchange, and a redirect or replay to an https URL then sends its request as a CONNECT too. Since AsyncHttpClient#2408, that attempt keeps the proxy's login after a cross-origin hop, or takes the login of the proxy it moves to, so it finds a tunnel an earlier exchange pooled to the new target. Until AsyncHttpClient#2410 the CONNECT was written into that tunnel, to the origin, with a preemptive Proxy-Authorization and the proxy's custom headers. Since AsyncHttpClient#2410 a CONNECT never takes a pooled channel, so the attempt opens another connection and tunnel to the proxy instead, and the pooled tunnel goes unused. Under a connection limit, that connection can be one too many: with maxConnections 2, a pooled tunnel and the plain http request hold both permits, and the redirect fails with TooManyConnectionsException although the tunnel it could take is idle in the pool. Clear the flag whenever an attempt sends the target, so that only the 407's own retry sees it, and the target takes the pooled tunnel, as it does when no 407 came before. Claude Code on behalf of Matthias Kurz Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes and one stronger test, following #2408. Both fixes concern behaviour released in 3.0.15.
Stop a stale 407 flag from forcing a CONNECT
Motivation: When AHC answers a proxy's 407 on a kept-alive connection, it flags the exchange so that the retry sends a CONNECT on the connection it holds. Only a tunnel that opens clears the flag. So after a 407 on a plain
httprequest, the flag stays set for the rest of the exchange, and a redirect or filter replay to anhttpsURL sends its request as a CONNECT too.Since #2408, that attempt keeps the proxy's login after a cross-origin hop, or takes the login of the proxy it moves to. The pool lookup is scoped by that login, so the attempt finds a tunnel that an earlier exchange pooled to the new target.
Proxy-Authorizationand the proxy's custom headers.maxConnections2, a pooled tunnel and the plainhttprequest hold both permits, and the redirect fails withTooManyConnectionsException, although the tunnel it could take is idle in the pool.Modification: The flag is cleared whenever an attempt sends the exchange's target request, so only the 407's own retry sees it.
Result: The redirected or replayed request takes the tunnel from the pool and is sent inside it, as it is when no 407 came earlier. It needs no further connection, so a connection limit no longer fails it.
Tests cover:
maxConnections2, where the redirect has to reuse the pooled tunnel;They check that nothing but the request reaches the origin, that the response is the redirected one, and that the pooled tunnel is reused.
Keep the raw URI when a request changes proxy
Motivation: When a retry, redirect or filter replay goes through a different proxy than the attempt before, AHC drops the
Proxy-Authorizationheader the request carries, because it was meant for the previous proxy (#2408). It did so by copying the request withRequest.toBuilder(), which always encodes the URI again. A request built with URL encoding disabled therefore reached the new proxy with a different request target:GET http://host/a|b?q={x}becameGET http://host/a%7Cb?q=%7Bx%7D. #2384 and #2393 fixed the sametoBuilder()effect for stored cookies and theRangeheader.Modification: A
DefaultRequestis copied with the raw URI encoder, through a privateRequestBuilderBasesubclass, asResumableAsyncHandlerdoes since #2393. Subclasses and otherRequestimplementations still go throughtoBuilder(), as they may override what it copies.Result: The request reaches the new proxy with the URI it was built with, minus the previous proxy's
Proxy-Authorization. No public API change.Check that a tunnel is pooled under its proxy
This commit only changes a test.
Motivation: The test for a selector that alternates between two proxies only counted CONNECTs. Suppose the request entering a freshly opened tunnel followed the selector to the other proxy. It would still be written on the channel it holds, so no second tunnel would open and the test would pass, while the channel is pooled under the other proxy's key.
Modification: A second request, selected through the proxy that opened the tunnel, has to reuse that tunnel from the pool.
Result: The test now fails if entering a tunnel moves the exchange to another proxy.
AI disclosure
Claude Code on behalf of Matthias Kurz. Every commit includes
Co-Authored-ByperAGENTS.md.Test plan
All on JDK 11. Docker was not running, so the skipped tests include the Testcontainers proxy tests.
./mvnw -B -ntp -Dgpg.skip=true clean verify: 2,497 tests, 0 failures, 22 skipped; Revapi passed against 3.0.15.ProxyConnectRetryTestandCallerContentLengthTestsuites: 172 tests, 0 failures. That run was onmainbefore the release commits and before the connection-limit test was added.ProxyReselectionTest5 times: 35 of 35 each time.TooManyConnectionsException: Too many connections: 2. The other two tests already pass without it, since Keep CONNECT and proxy login out of established tunnels #2410: one checks that the proxy's custom header does not reach the origin, and one is the guard where no tunnel is pooled./a%7Cb?q=%7Bx%7D.