Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip ALPN if request is HTTP endpoint #5854

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

davidh44
Copy link
Contributor

@davidh44 davidh44 commented Feb 3, 2025

Motivation and Context

Mock tests with h2 clients making requests to HTTP endpoints fail with recent ALPN addition

Modifications

Skip adding ALPN handler if request endpoint is HTTP and the default client setting is ALPN. This maintains previous behavior of prior knowledge protocol negotiation, and avoids breaking changes for existing generated clients with h2 protocol setting

Continue to throw error if request endpoint is HTTP and user configures ALPN on client

Testing

Added unit tests

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

@davidh44 davidh44 requested a review from a team as a code owner February 3, 2025 23:25
@@ -99,7 +99,9 @@ public void channelCreated(Channel ch) {
ch.attr(CHANNEL_DIAGNOSTICS).set(new ChannelDiagnostics(ch));
ch.attr(PROTOCOL_FUTURE).set(new CompletableFuture<>());
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {

boolean sslCtxPresent = sslCtx != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

whats the reason for this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are saving the boolean as variable since we pass to configureProtocolHandlers() to fallback to prior knowledge if sslCtx is null

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have test cases for this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is existing behavior, to use prior knowledge. Covered by test here, to make sure we don't throw UnsupportedOperationException

assertThat(e.getMessage()).doesNotContain("ALPN can only be used with HTTPS, not HTTP");

throw new UnsupportedOperationException("ALPN can only be used with HTTPS, not HTTP.");
}
if (protocolNegotiation == ProtocolNegotiation.ALPN) {
log.debug(null, () -> "Default client protocol negotiation is ALPN, but request endpoint is HTTP. Prior "
Copy link
Contributor

Choose a reason for hiding this comment

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

This log will be logged for every request. What is the significance of this log, as in if the default ALPN is not supported for the service, won't we immediately get server-side exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed offline, will remove logging. We fallback to prior knowledge in ChannelPipelineInitializer. This scenario of ALPN default setting with HTTP endpoint should only be present in mock tests

@@ -99,7 +99,9 @@ public void channelCreated(Channel ch) {
ch.attr(CHANNEL_DIAGNOSTICS).set(new ChannelDiagnostics(ch));
ch.attr(PROTOCOL_FUTURE).set(new CompletableFuture<>());
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {

boolean sslCtxPresent = sslCtx != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have test cases for this change ?

@joviegas
Copy link
Contributor

joviegas commented Feb 4, 2025

Can we please add change logs .

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