23 |
23 |
24 import com.sun.net.httpserver.HttpsConfigurator; |
24 import com.sun.net.httpserver.HttpsConfigurator; |
25 import com.sun.net.httpserver.HttpsServer; |
25 import com.sun.net.httpserver.HttpsServer; |
26 import jdk.testlibrary.SimpleSSLContext; |
26 import jdk.testlibrary.SimpleSSLContext; |
27 import javax.net.ssl.SSLContext; |
27 import javax.net.ssl.SSLContext; |
|
28 import java.net.InetAddress; |
28 import java.net.InetSocketAddress; |
29 import java.net.InetSocketAddress; |
29 import java.net.ProxySelector; |
30 import java.net.ProxySelector; |
30 import java.net.URI; |
31 import java.net.URI; |
31 import java.net.http.HttpClient; |
32 import java.net.http.HttpClient; |
32 import java.net.http.HttpClient.Version; |
33 import java.net.http.HttpClient.Version; |
95 .proxy(ps); |
96 .proxy(ps); |
96 return builder.build(); |
97 return builder.build(); |
97 } |
98 } |
98 |
99 |
99 public static void main(String[] args) throws Exception { |
100 public static void main(String[] args) throws Exception { |
100 InetSocketAddress sa = new InetSocketAddress(0); |
101 InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
101 HttpsServer server1 = HttpsServer.create(sa, 0); |
102 HttpsServer server1 = HttpsServer.create(sa, 0); |
102 server1.setHttpsConfigurator(new HttpsConfigurator(context)); |
103 server1.setHttpsConfigurator(new HttpsConfigurator(context)); |
103 HttpTestServer http1Server = |
104 HttpTestServer http1Server = |
104 HttpTestServer.of(server1); |
105 HttpTestServer.of(server1); |
105 http1Server.addHandler(new HttpTestEchoHandler(), "/"); |
106 http1Server.addHandler(new HttpTestEchoHandler(), "/"); |
106 http1Server.start(); |
107 http1Server.start(); |
107 HttpTestServer http2Server = HttpTestServer.of( |
108 HttpTestServer http2Server = HttpTestServer.of( |
108 new Http2TestServer("127.0.0.1", true, 0)); |
109 new Http2TestServer("localhost", true, 0)); |
109 http2Server.addHandler(new HttpTestEchoHandler(), "/"); |
110 http2Server.addHandler(new HttpTestEchoHandler(), "/"); |
110 http2Server.start(); |
111 http2Server.start(); |
111 |
112 |
112 DigestEchoServer.TunnelingProxy proxy = DigestEchoServer.createHttpsProxyTunnel( |
113 DigestEchoServer.TunnelingProxy proxy = DigestEchoServer.createHttpsProxyTunnel( |
113 DigestEchoServer.HttpAuthSchemeType.NONE); |
114 DigestEchoServer.HttpAuthSchemeType.NONE); |
114 |
115 |
115 try { |
116 try { |
116 URI uri1 = new URI("https:/" + http1Server.getAddress() + "/foo/https1"); |
117 URI uri1 = new URI("https://" + http1Server.serverAuthority() + "/foo/https1"); |
117 URI uri2 = new URI("https:/" + http2Server.getAddress() + "/foo/https2"); |
118 URI uri2 = new URI("https://" + http2Server.serverAuthority() + "/foo/https2"); |
118 ProxySelector ps = ProxySelector.of(proxy.getProxyAddress()); |
119 ProxySelector ps = ProxySelector.of(proxy.getProxyAddress()); |
119 //HttpClient.Builder.NO_PROXY; |
120 //HttpClient.Builder.NO_PROXY; |
120 HttpsTunnelTest test = new HttpsTunnelTest(); |
121 HttpsTunnelTest test = new HttpsTunnelTest(); |
121 HttpClient client = test.newHttpClient(ps); |
122 HttpClient client = test.newHttpClient(ps); |
122 out.println("Proxy is: " + ps.select(uri2)); |
123 out.println("Proxy is: " + ps.select(uri2)); |