RFR: 8209137: Add ability to bind to specific local address to HTTP client

Daniel Fuchs dfuchs at openjdk.java.net
Fri Dec 10 09:34:44 UTC 2021


On Fri, 3 Dec 2021 17:28:25 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> This change proposes to implement the enhancement noted in https://bugs.openjdk.java.net/browse/JDK-8209137.
>> 
>> The change introduces a new API to allow applications to build a `java.net.http.HTTPClient` configured with a specific local address that will be used while creating `Socket`(s) for connections.
>
> test/jdk/java/net/httpclient/HttpClientLocalAddrTest.java line 74:
> 
>> 72: 
>> 73:     @BeforeClass
>> 74:     public static void beforeClass() throws Exception {
> 
> For HttpClient tests - unless they are specific to HTTP/1.1 I'd recommend making the test class implement HttpServerAdapters and test will all versions of the protocol (http, https, http/2, and https/2).
> An example can be found in e.g. `test/jdk/java/net/httpclient/CancelRequestTest.java`

Also it's better if the test is IP version agnostic.

> test/jdk/java/net/httpclient/HttpClientLocalAddrTest.java line 205:
> 
>> 203:             // anyAddress
>> 204:             if (Boolean.getBoolean("java.net.preferIPv6Addresses")) {
>> 205:                 // ipv6 wildcard
> 
> ::1 is the ipv6 loopback - not the ipv6 wildcard

You may encounter some issues when testing with https and IPv6 - Michael is working on a fix to add the loopback addresses as SNI aliases to the SimpleSSLContext certificate:
https://bugs.openjdk.java.net/browse/JDK-8278312

-------------

PR: https://git.openjdk.java.net/jdk/pull/6690


More information about the net-dev mailing list