|
1 | 1 | /* |
2 | | - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -108,6 +108,7 @@ public class HttpsTunnelAuthTest implements HttpServerAdapters, AutoCloseable { |
108 | 108 | } |
109 | 109 |
|
110 | 110 | void setUp() throws IOException { |
| 111 | + HttpServerAdapters.enableServerLogging(); |
111 | 112 | // Creates an HTTP/1.1 Server that will authenticate for |
112 | 113 | // arthur with password dent |
113 | 114 | http1Server = DigestEchoServer.createServer(Version.HTTP_1_1, |
@@ -143,10 +144,8 @@ void setUp() throws IOException { |
143 | 144 |
|
144 | 145 | // Creates a proxy selector that unconditionally select the |
145 | 146 | // above proxy. |
146 | | - var ps = proxySelector = ProxySelector.of(proxy.getProxyAddress()); |
| 147 | + proxySelector = ProxySelector.of(proxy.getProxyAddress()); |
147 | 148 |
|
148 | | - // Creates a client that uses the above proxy selector |
149 | | - client = newHttpClient(ps); |
150 | 149 | } |
151 | 150 |
|
152 | 151 | @Override |
@@ -177,23 +176,26 @@ public static void main(String[] args) throws Exception { |
177 | 176 | try (HttpsTunnelAuthTest test = new HttpsTunnelAuthTest()) { |
178 | 177 | test.setUp(); |
179 | 178 |
|
180 | | - // tests proxy and server authentication through: |
181 | | - // - plain proxy connection to plain HTTP/1.1 server, |
182 | | - test.test(Version.HTTP_1_1, "http", "/foo/http1"); |
| 179 | + try (HttpClient client = test.newHttpClient(test.proxySelector)) { |
| 180 | + // tests proxy and server authentication through: |
| 181 | + // - plain proxy connection to plain HTTP/1.1 server, |
| 182 | + test.test(client, Version.HTTP_1_1, "http", "/foo/http1"); |
| 183 | + } |
183 | 184 |
|
184 | 185 | // can't really test plain proxy connection to plain HTTP/2 server: |
185 | 186 | // this is not supported: we downgrade to HTTP/1.1 in that case |
186 | 187 | // so that is actually somewhat equivalent to the first case: |
187 | 188 | // therefore we will use a new client to force re-authentication |
188 | 189 | // of the proxy connection. |
189 | | - test.client = test.newHttpClient(test.proxySelector); |
190 | | - test.test(Version.HTTP_2, "http", "/foo/http2"); |
| 190 | + try (HttpClient client = test.newHttpClient(test.proxySelector)) { |
| 191 | + test.test(client, Version.HTTP_2, "http", "/foo/http2"); |
191 | 192 |
|
192 | | - // - proxy tunnel SSL connection to HTTP/1.1 server |
193 | | - test.test(Version.HTTP_1_1, "https", "/foo/https1"); |
| 193 | + // - proxy tunnel SSL connection to HTTP/1.1 server |
| 194 | + test.test(client, Version.HTTP_1_1, "https", "/foo/https1"); |
194 | 195 |
|
195 | | - // - proxy tunnel SSl connection to HTTP/2 server |
196 | | - test.test(Version.HTTP_2, "https", "/foo/https2"); |
| 196 | + // - proxy tunnel SSl connection to HTTP/2 server |
| 197 | + test.test(client, Version.HTTP_2, "https", "/foo/https2"); |
| 198 | + } |
197 | 199 | } |
198 | 200 | } |
199 | 201 |
|
@@ -227,14 +229,14 @@ Version expectedVersion(String scheme, Version version) { |
227 | 229 | return "http".equals(scheme) ? Version.HTTP_1_1 : version; |
228 | 230 | } |
229 | 231 |
|
230 | | - public void test(Version version, String scheme, String path) throws Exception { |
| 232 | + public void test(HttpClient client, Version version, String scheme, String path) throws Exception { |
231 | 233 | System.out.printf("%nTesting %s, %s, %s%n", version, scheme, path); |
232 | 234 | DigestEchoServer server = server(scheme, version); |
233 | 235 | try { |
234 | 236 |
|
235 | 237 | URI uri = jdk.test.lib.net.URIBuilder.newBuilder() |
236 | 238 | .scheme(scheme) |
237 | | - .host("localhost") |
| 239 | + .loopback() |
238 | 240 | .port(server.getServerAddress().getPort()) |
239 | 241 | .path(path).build(); |
240 | 242 |
|
|
0 commit comments