Skip to content

Support HTTP/2 after proxy CONNECT#2250

Merged
hyperxpro merged 3 commits into
AsyncHttpClient:mainfrom
rampreeth:codex/http2-after-proxy-connect
Jul 23, 2026
Merged

Support HTTP/2 after proxy CONNECT#2250
hyperxpro merged 3 commits into
AsyncHttpClient:mainfrom
rampreeth:codex/http2-after-proxy-connect

Conversation

@rampreeth

@rampreeth rampreeth commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Motivation

When an HTTPS request uses an HTTP proxy, AHC establishes a CONNECT tunnel and then performs TLS with the target. If ALPN selects h2, the tunnel path currently leaves the HTTP/1.1 codec in place. The target then receives HTTP/1.1 bytes on a connection that negotiated HTTP/2 and closes it.

Modification

  • Check the negotiated ALPN protocol after the target TLS handshake in both proxy tunnel paths.
  • When ALPN selects h2, upgrade the existing channel pipeline to HTTP/2 and register the physical tunnel connection with its existing pool partition key.
  • Preserve the existing HTTP/1.1 fallback and WebSocket behavior.
  • Add regression tests using local HTTP and HTTPS CONNECT proxies with a TLS HTTP/2 target.
  • Verify that the upgraded tunnel is registered and reused for a second request.
  • Preserve the existing public tunneling method signatures for binary compatibility.

Result

HTTPS requests through HTTP and HTTPS CONNECT proxies now send HTTP/2 frames when the target negotiates h2. The regression tests verify successful HTTP/2 responses and reuse of a single physical target connection.

Testing

  • ./mvnw -pl client -Dtest=BasicHttp2Test,HttpsProxyTest test — 60 tests passed.
  • Full client test suite passed as part of verify; the local run then stopped at artifact signing because gpg is not installed.
  • ./mvnw -pl client -DskipTests -Dgpg.skip=true verify — packaging and API compatibility checks passed.

Fixes #2241

@rampreeth
rampreeth marked this pull request as ready for review July 18, 2026 12:16

@hyperxpro hyperxpro left a comment

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.

Not in this PR's diff, so leaving it here: this change makes HTTP/2 after CONNECT work, which makes the workaround in client/src/test/java/org/asynchttpclient/proxy/HttpsProxyTestcontainersIntegrationTest.java stale and its comment misleading. Could you remove .setHttp2Enabled(false) and the // HTTP/2 ALPN upgrade after proxy CONNECT tunnel is not yet supported comment in both testHttpProxyToHttpsTarget (lines 149-150) and testHttpsProxyToHttpsTarget (lines 172-173)? That lets those external tests exercise the new HTTP/2-through-proxy path instead of forcing HTTP/1.1, and the comment stops claiming something that is no longer true.

Comment thread client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java Outdated
Comment thread client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java Outdated
Comment thread client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java Outdated
Comment thread client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java Outdated
Comment thread client/src/test/java/org/asynchttpclient/BasicHttp2Test.java
@rampreeth

rampreeth commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Done - removed .setHttp2Enabled(false) and the stale comment from both proxy-to-HTTPS Testcontainers tests. They now use the default HTTP/2-enabled configuration.

@rampreeth
rampreeth requested a review from hyperxpro July 19, 2026 02:47
@rampreeth

Copy link
Copy Markdown
Contributor Author

Hi @hyperxpro, just a gentle reminder when you get a chance. I've addressed the review comments and would appreciate a re-review. Thanks!

@hyperxpro
hyperxpro merged commit f341bac into AsyncHttpClient:main Jul 23, 2026
13 checks passed
@hyperxpro

Copy link
Copy Markdown
Member

Thanks a lot!

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.

HTTP/2 can be negotiated after proxy CONNECT, but AHC still sends HTTP/1.1

2 participants