57 * For instance: |
57 * For instance: |
58 * <pre>{@code |
58 * <pre>{@code |
59 * |
59 * |
60 * URI http1URI, http2URI; |
60 * URI http1URI, http2URI; |
61 * |
61 * |
62 * InetSocketAddress sa = new InetSocketAddress("localhost", 0); |
62 * InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
63 * HttpTestServer server1 = HttpTestServer.of(HttpServer.create(sa, 0)); |
63 * HttpTestServer server1 = HttpTestServer.of(HttpServer.create(sa, 0)); |
64 * HttpTestContext context = server.addHandler(new HttpTestEchoHandler(), "/http1/echo"); |
64 * HttpTestContext context = server.addHandler(new HttpTestEchoHandler(), "/http1/echo"); |
65 * http2URI = "http://127.0.0.1:" + server1.getAddress().getPort() + "/http1/echo"; |
65 * http2URI = "http://localhost:" + server1.getAddress().getPort() + "/http1/echo"; |
66 * |
66 * |
67 * Http2TestServer http2TestServer = new Http2TestServer("127.0.0.1", false, 0); |
67 * Http2TestServer http2TestServer = new Http2TestServer("localhost", false, 0); |
68 * HttpTestServer server2 = HttpTestServer.of(http2TestServer); |
68 * HttpTestServer server2 = HttpTestServer.of(http2TestServer); |
69 * server2.addHandler(new HttpTestEchoHandler(), "/http2/echo"); |
69 * server2.addHandler(new HttpTestEchoHandler(), "/http2/echo"); |
70 * http1URI = "http://127.0.0.1:" + server2.getAddress().getPort() + "/http2/echo"; |
70 * http1URI = "http://localhost:" + server2.getAddress().getPort() + "/http2/echo"; |
71 * |
71 * |
72 * }</pre> |
72 * }</pre> |
73 */ |
73 */ |
74 public interface HttpServerAdapters { |
74 public interface HttpServerAdapters { |
75 |
75 |
481 + "]::addHandler " + handler + ", " + path); |
481 + "]::addHandler " + handler + ", " + path); |
482 return new Http1TestContext(impl.createContext(path, handler.toHttpHandler())); |
482 return new Http1TestContext(impl.createContext(path, handler.toHttpHandler())); |
483 } |
483 } |
484 @Override |
484 @Override |
485 public InetSocketAddress getAddress() { |
485 public InetSocketAddress getAddress() { |
486 return new InetSocketAddress("127.0.0.1", |
486 return new InetSocketAddress(InetAddress.getLoopbackAddress(), |
487 impl.getAddress().getPort()); |
487 impl.getAddress().getPort()); |
488 } |
488 } |
489 public Version getVersion() { return Version.HTTP_1_1; } |
489 public Version getVersion() { return Version.HTTP_1_1; } |
490 } |
490 } |
491 |
491 |
531 impl.addHandler(context.toHttp2Handler(), path); |
531 impl.addHandler(context.toHttp2Handler(), path); |
532 return context; |
532 return context; |
533 } |
533 } |
534 @Override |
534 @Override |
535 public InetSocketAddress getAddress() { |
535 public InetSocketAddress getAddress() { |
536 return new InetSocketAddress("127.0.0.1", |
536 return new InetSocketAddress(InetAddress.getLoopbackAddress(), |
537 impl.getAddress().getPort()); |
537 impl.getAddress().getPort()); |
538 } |
538 } |
539 public Version getVersion() { return Version.HTTP_2; } |
539 public Version getVersion() { return Version.HTTP_2; } |
540 } |
540 } |
541 |
541 |