Skip to content

Keep the raw URI in tunnels and auth retries - #2414

Open
mkurz wants to merge 1 commit into
AsyncHttpClient:mainfrom
mkurz:fix/raw-uri-in-tunnels-and-auth-retries
Open

mkurz wants to merge 1 commit into
AsyncHttpClient:mainfrom
mkurz:fix/raw-uri-in-tunnels-and-auth-retries

Conversation

@mkurz

@mkurz mkurz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Motivation: Three interceptors send a copy of the request they handle, made with Request.toBuilder():

  • ConnectSuccessInterceptor, for the first request in a new tunnel, once the proxy accepts the CONNECT;
  • Unauthorized401Interceptor and ProxyUnauthorized407Interceptor, for the retry with credentials.

toBuilder() encodes the URI again, so a request built with URL encoding disabled was sent with a different request target: /a|b?q={x} went out as /a%7Cb?q=%7Bx%7D. That hit the https, wss or ws request that opens a tunnel through an HTTP or HTTPS proxy, every retry after a 401, and every retry after a 407 to an http request. A request that takes a pooled tunnel is not copied. #2384 and #2393 fixed the same toBuilder() effect for stored cookies and the Range header, and #2412 does for a request that changes proxy.

Modification: A DefaultRequest is copied with the raw URI encoder, through one package-private RequestBuilderBase subclass that the three interceptors share, as ResumableAsyncHandler does since #2393. Subclasses and other Request implementations still go through toBuilder(), as they may override what it copies. CallerCookies.refresh, which gets the retry's builder, now takes any RequestBuilderBase.

Result: For a DefaultRequest, the origin, or the proxy for an http request, receives the request target as the request was built: on the first request in a new tunnel, and on each retry with credentials. Another Request implementation keeps the copy its own toBuilder() makes. A request built with URL encoding enabled is sent as before.

Tests:

  • HttpsProxyTest:
    • an https request through an HTTP proxy, built with URL encoding disabled and enabled, to an origin that records the request target as it arrived;
    • a DefaultRequest subclass, whose own toBuilder() still makes the tunnel's request.
  • AuthRetryRawUriTest: Basic and Digest retries after a 401 and after a 407, plus a guard with URL encoding enabled. The server accepts any credentials, so these check the request target only.

Reverting any one of the five copies fails exactly its own test, and so does matching the class with instanceof.

Not changed: this doesn't cover every internal copy.

AI disclosure

Claude Code on behalf of Matthias Kurz. The commit includes Co-Authored-By per AGENTS.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,499 tests, 0 failures, 22 skipped; Revapi passed against 3.0.15.
  • AuthRetryRawUriTest and HttpsProxyTest 5 times: 20 of 20 each time.
  • Each change reverted on its own: the 401 Digest and general retries, the 407 Digest and general retries, and the tunnel each fail exactly their own test. instanceof instead of the exact class fails the subclass test.

Three interceptors send a copy of the request they handle, made with
toBuilder(): ConnectSuccessInterceptor for the first request in a new
tunnel, and the 401 and 407 interceptors for the retry with
credentials. toBuilder() encodes the URI again, so a request built
with URL encoding disabled was sent encoded: /a|b?q={x} went out as
/a%7Cb?q=%7Bx%7D. That hit the https, wss or ws request that opens a
tunnel through an HTTP or HTTPS proxy, every retry after a 401, and
every retry after a 407 to an http request. A request that takes a
pooled tunnel is not copied.

Copy a DefaultRequest with URL encoding disabled instead, as AsyncHttpClient#2393
does for a Range header, through one package-private builder that the
three interceptors share. Another Request implementation still goes
through its own toBuilder(), which copies it as before. The copies are
still copies, so nothing else about them changes.

Claude Code on behalf of Matthias Kurz

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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