Skip to content

Conversation

@devalkone
Copy link

Fixes #9826

Description

This PR adds support for custom HTTP headers in HTTP CONNECT proxy connections, as requested in #9826.

Currently, HttpConnectProxiedSocketAddress only supports username and password for proxy authentication. However, HTTP/1.1 CONNECT supports arbitrary headers. This change adds a headers field to allow users to pass custom headers to the proxy.

Changes

  • Added headers field to HttpConnectProxiedSocketAddress
  • Added setHeaders() method to Builder
  • Updated ProtocolNegotiators.httpProxy() to convert headers to Netty's HttpHeaders
  • Headers are immutable after building (defensive copy)

Testing

  • Added 12 unit tests for HttpConnectProxiedSocketAddress
  • Added integration test httpProxy_customHeaders() in ProtocolNegotiatorsTest
  • Updated existing httpProxy tests for new signature
  • All existing tests pass (backward-compatible)
  • Verified OkHttp compatibility

Backward Compatibility

This is a fully backward-compatible change. The headers field defaults to an empty map if not set, so existing code continues to work without modifications.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 5, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: devalkone / name: Alexey Konyagin (25d026c)

@devalkone devalkone force-pushed the proxy-custom-headers branch 2 times, most recently from 2ce7276 to 484d810 Compare November 5, 2025 12:00
@devalkone devalkone marked this pull request as ready for review November 5, 2025 12:13
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

This looks great. One easy change for the experimental API.

/**
* Returns the headers associated with this proxied socket address.
*/
public Map<String, String> getHeaders() {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add @ExperimentalApi here and to the setter. We add it to all new APIs. This seems easy to stabilize.

You can look around for some examples, but basically you create a tracking issue and use the URL in the annotation.

Copy link
Author

Choose a reason for hiding this comment

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

Done! Added @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12479") to both getHeaders() and setHeaders().

Used #12479 as tracking issue.

Allow users to specify custom HTTP headers when connecting through
an HTTP CONNECT proxy. This extends HttpConnectProxiedSocketAddress
with an optional headers field (Map<String, String>), which is
converted to Netty's HttpHeaders in the protocol negotiator.

This change is fully backward-compatible. Existing code without
headers continues to work as before.

Fixes grpc#9826
@devalkone devalkone force-pushed the proxy-custom-headers branch from 484d810 to 25d026c Compare November 6, 2025 08:27
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.

Add header support to HttpConnectProxiedSocketAddress

2 participants