Skip to content

8361060: Keep track of the origin server against which a jdk.internal.net.http.HttpConnection was constructed #26041

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

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

Conversation

jaikiran
Copy link
Member

@jaikiran jaikiran commented Jun 30, 2025

Can I please get a review of this change which updates the jdk.internal.net.http.HttpConnection to keep track of the origin server for which the HttpConnection was constructed? This addresses https://bugs.openjdk.org/browse/JDK-8361060.

This is an internal implementation change which will allow other parts of the JDK's HttpClient implementation to use the origin server information. An example of such usage is the alternate services that are going to be supported in the JDK's HttpClient upcoming implementation for HTTP/3.

No new tests have been introduced and existing tests in tier1, tier2 and tier3 continue to pass.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8361060: Keep track of the origin server against which a jdk.internal.net.http.HttpConnection was constructed (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26041/head:pull/26041
$ git checkout pull/26041

Update a local copy of the PR:
$ git checkout pull/26041
$ git pull https://git.openjdk.org/jdk.git pull/26041/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26041

View PR using the GUI difftool:
$ git pr show -t 26041

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26041.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 30, 2025

👋 Welcome back jpai! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 30, 2025

@jaikiran This change is no longer ready for integration - check the PR body for details.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 30, 2025
@openjdk
Copy link

openjdk bot commented Jun 30, 2025

@jaikiran The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the net net-dev@openjdk.org label Jun 30, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 30, 2025

Webrevs

HttpClientImpl client,
String[] alpn,
String label) {
super(addr, client, Utils.getServerName(addr), addr.getPort(), alpn, label);
plainConnection = new PlainHttpConnection(addr, client, label);
super(originServer, addr, client, Utils.getServerName(addr), addr.getPort(), alpn, label);
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need Utils.getServerName(addr), addr.getPort(), now that we have originServer? Or in other words - should we base these calls on the addr parameter or on the originServer parameters?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a look at it and you are right - with the introduction of this Origin construct, it should now be possible (and in fact prefered) to use it for constructing the SNI names. I updated this code to use the Origin instance.

While doing that, the change caused a test failure which exposed one detail that I hadn't considered. java.net.URI.getHost() is specified to return a IPv6 address enclosed in square brackets. The Origin class hadn't considered that previously. It's now been updated to strip the square brackets when constructing the host value. This will allow the Origin.host() to be used in places where it was/is being used as a host that might be returned from a InetAddress. Local testing with this change now passes all the tests. I'll now trigger tier testing in our CI.

HttpClientImpl client,
String[] alpn,
InetSocketAddress proxy,
ProxyHeaders proxyHeaders,
String label)
{
super(addr, client, Utils.getServerName(addr), addr.getPort(), alpn, label);
this.plainConnection = new PlainTunnelingConnection(addr, proxy, client, proxyHeaders, label);
super(originServer, addr, client, Utils.getServerName(addr), addr.getPort(), alpn, label);
Copy link
Member

Choose a reason for hiding this comment

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

Same question

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to use the Origin instance.

}
return host + ":" + port;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Missing newline.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 41 to 48
public record Origin(String scheme, String host, int port) {
public Origin {
Objects.requireNonNull(scheme);
Objects.requireNonNull(host);
if (port <= 0) {
throw new IllegalArgumentException("Invalid port");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we enforce lower case for scheme and host in this constructor?
For instance - convert to lower case if needed in from(URI) and throw/assert here if not lower case?

Copy link
Member Author

Choose a reason for hiding this comment

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

We only support http and https. So I think it makes sense to convert it to lower case and expect the scheme to be either of these. I've updated the PR accordingly.

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

Looks good. I wonder if we should lower case the host returned by getHost() too (when not a literal address).

@jaikiran
Copy link
Member Author

jaikiran commented Jul 2, 2025

I wonder if we should lower case the host returned by getHost() too (when not a literal address).

Done. The PR has been updated with this change. tier1, tier2 and tier3 test pass with this change. Given the kind of code we added in this Origin class, I'm now considering introducing a test for this class' behaviour. I'll update this PR shortly.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 2, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jul 2, 2025
@jaikiran
Copy link
Member Author

jaikiran commented Jul 2, 2025

I've updated the PR to include a test for the Origin class. No other changes. The test passes with these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net net-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants