@Override protected void startInternal() { DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block(); setPort(server.address().getPort()); this.serverRef.set(server); }
@Override protected void startInternal() { DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block(); setPort(server.address().getPort()); this.serverRef.set(server); }
@Override protected void startInternal() { DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block(); setPort(server.address().getPort()); this.serverRef.set(server); }
@Override public InetSocketAddress address() { return server.address(); }
@Override public InetSocketAddress address() { return server.address(); }
/** * Return the server's host String. That is, the hostname or in case the server was bound * to a literal IP address, the IP string representation (rather than performing a reverse-DNS * lookup). * * @return the host string, without reverse DNS lookup * @see DisposableChannel#address() * @see InetSocketAddress#getHostString() */ default String host() { return address().getHostString(); }
/** * Return this server's port. * @return The port the server is bound to. */ default int port() { return address().getPort(); } }
/** * Return this server's port. * @return The port the server is bound to. */ default int port() { return address().getPort(); } }
private InetSocketAddress address(DisposableServer runningServer) { return runningServer.address(); }
@Override public void dispose() { server.dispose(); HttpResources.get() .disposeWhen(server.address()); }
@Override public void dispose() { server.dispose(); HttpResources.get() .disposeWhen(server.address()); }
@Test public void forwardedHost() { testClientRequest( clientRequestHeaders -> clientRequestHeaders.add("Forwarded", "host=192.168.0.1"), serverRequest -> { Assertions.assertThat(serverRequest.hostAddress().getHostString()).isEqualTo("192.168.0.1"); Assertions.assertThat(serverRequest.hostAddress().getPort()).isEqualTo(this.connection.address().getPort()); }); }
@Test public void forwardedMultipleHosts() { testClientRequest( clientRequestHeaders -> clientRequestHeaders.add("Forwarded", "host=a.example.com,host=b.example.com, host=c.example.com"), serverRequest -> { Assertions.assertThat(serverRequest.hostAddress().getHostString()).isEqualTo("a.example.com"); Assertions.assertThat(serverRequest.hostAddress().getPort()).isEqualTo(this.connection.address().getPort()); }); }
@Test public void forwardedHostIpV6() { testClientRequest( clientRequestHeaders -> clientRequestHeaders.add("Forwarded", "host=[1abc:2abc:3abc::5ABC:6abc]"), serverRequest -> { Assertions.assertThat(serverRequest.hostAddress().getHostString()).isEqualTo("1abc:2abc:3abc:0:0:0:5abc:6abc"); Assertions.assertThat(serverRequest.hostAddress().getPort()).isEqualTo(this.connection.address().getPort()); }); }
@Test public void xForwardedHost() { testClientRequest( clientRequestHeaders -> clientRequestHeaders.add("X-Forwarded-Host", "[1abc:2abc:3abc::5ABC:6abc], 192.168.0.1"), serverRequest -> { Assertions.assertThat(serverRequest.hostAddress().getHostString()).isEqualTo("1abc:2abc:3abc:0:0:0:5abc:6abc"); Assertions.assertThat(serverRequest.hostAddress().getPort()).isEqualTo(this.connection.address().getPort()); }); }
@Test public void noHeaders() { testClientRequest( clientRequestHeaders -> {}, serverRequest -> { Assertions.assertThat(serverRequest.hostAddress().getHostString()) .containsPattern("^0:0:0:0:0:0:0:1(%\\w*)?|127.0.0.1$"); Assertions.assertThat(serverRequest.hostAddress().getPort()).isEqualTo(this.connection.address().getPort()); }); }
@Test public void httpPort() { DisposableServer blockingFacade = HttpServer.create() .port(8080) .handle((req, resp) -> resp.sendNotFound()) .wiretap(true) .bindNow(); blockingFacade.disposeNow(); assertThat(blockingFacade.address().getPort()) .isEqualTo(8080); }
@Test public void httpPortWithAddress() { DisposableServer blockingFacade = HttpServer.create() .port(8080) .host("localhost") .handle((req, resp) -> resp.sendNotFound()) .wiretap(true) .bindNow(); blockingFacade.disposeNow(); assertThat(blockingFacade.address().getPort()) .isEqualTo(8080); }
private Mono<List<String>> getClientDataPromise() { HttpClient httpClient = HttpClient.create() .port(httpServer.address().getPort()) .wiretap(true); return httpClient.get() .uri("/data") .responseContent() .asString() .log("client") .collectList() .cache() .toProcessor(); }