42 import com.sun.net.httpserver.HttpsConfigurator; |
42 import com.sun.net.httpserver.HttpsConfigurator; |
43 import com.sun.net.httpserver.HttpsServer; |
43 import com.sun.net.httpserver.HttpsServer; |
44 import java.io.IOException; |
44 import java.io.IOException; |
45 import java.io.InputStream; |
45 import java.io.InputStream; |
46 import java.io.OutputStream; |
46 import java.io.OutputStream; |
|
47 import java.net.InetAddress; |
47 import java.net.InetSocketAddress; |
48 import java.net.InetSocketAddress; |
48 import java.net.URI; |
49 import java.net.URI; |
49 import java.nio.ByteBuffer; |
50 import java.nio.ByteBuffer; |
50 import java.util.Arrays; |
51 import java.util.Arrays; |
51 import java.util.Optional; |
52 import java.util.Optional; |
312 return; // already cancelled |
313 return; // already cancelled |
313 } |
314 } |
314 } |
315 } |
315 } |
316 } |
316 |
317 |
|
318 static String serverAuthority(HttpServer server) { |
|
319 return InetAddress.getLoopbackAddress().getHostName() + ":" |
|
320 + server.getAddress().getPort(); |
|
321 } |
|
322 |
317 @BeforeTest |
323 @BeforeTest |
318 public void setup() throws Exception { |
324 public void setup() throws Exception { |
319 sslContext = new SimpleSSLContext().get(); |
325 sslContext = new SimpleSSLContext().get(); |
320 if (sslContext == null) |
326 if (sslContext == null) |
321 throw new AssertionError("Unexpected null sslContext"); |
327 throw new AssertionError("Unexpected null sslContext"); |
322 |
328 |
323 InetSocketAddress sa = new InetSocketAddress("localhost", 0); |
329 InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
324 httpTestServer = HttpServer.create(sa, 0); |
330 httpTestServer = HttpServer.create(sa, 0); |
325 httpTestServer.createContext("/http1/echo", new Http1EchoHandler()); |
331 httpTestServer.createContext("/http1/echo", new Http1EchoHandler()); |
326 httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/echo"; |
332 httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/echo"; |
327 |
333 |
328 httpsTestServer = HttpsServer.create(sa, 0); |
334 httpsTestServer = HttpsServer.create(sa, 0); |
329 httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); |
335 httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); |
330 httpsTestServer.createContext("/https1/echo", new Http1EchoHandler()); |
336 httpsTestServer.createContext("/https1/echo", new Http1EchoHandler()); |
331 httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/echo"; |
337 httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/echo"; |
332 |
338 |
333 http2TestServer = new Http2TestServer("127.0.0.1", false, 0); |
339 http2TestServer = new Http2TestServer("localhost", false, 0); |
334 http2TestServer.addHandler(new Http2EchoHandler(), "/http2/echo"); |
340 http2TestServer.addHandler(new Http2EchoHandler(), "/http2/echo"); |
335 int port = http2TestServer.getAddress().getPort(); |
341 http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/echo"; |
336 http2URI = "http://127.0.0.1:" + port + "/http2/echo"; |
342 |
337 |
343 https2TestServer = new Http2TestServer("localhost", true, 0); |
338 https2TestServer = new Http2TestServer("127.0.0.1", true, 0); |
|
339 https2TestServer.addHandler(new Http2EchoHandler(), "/https2/echo"); |
344 https2TestServer.addHandler(new Http2EchoHandler(), "/https2/echo"); |
340 port = https2TestServer.getAddress().getPort(); |
345 https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/echo"; |
341 https2URI = "https://127.0.0.1:" + port + "/https2/echo"; |
|
342 |
346 |
343 httpTestServer.start(); |
347 httpTestServer.start(); |
344 httpsTestServer.start(); |
348 httpsTestServer.start(); |
345 http2TestServer.start(); |
349 http2TestServer.start(); |
346 https2TestServer.start(); |
350 https2TestServer.start(); |