use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.
the class HttpTest method testHAProxyProtocolAccepted.
private void testHAProxyProtocolAccepted(Buffer header, SocketAddress remote, SocketAddress local) throws Exception {
/*
* In case remote / local is null then we will use the connected remote / local address from the proxy. This is needed
* in order to test unknown protocol since we will use the actual connected addresses and ports.
* This is only valid when testAddress is an InetSocketAddress. If testAddress is a DomainSocketAddress then
* remoteAddress and localAddress are null
*
* Have in mind that proxies connectionRemoteAddress is the server request local address and proxies connectionLocalAddress is the
* server request remote address.
* */
waitFor(2);
HAProxy proxy = new HAProxy(testAddress, header);
proxy.start(vertx);
server.close();
server = vertx.createHttpServer(createBaseServerOptions().setUseProxyProtocol(true)).requestHandler(req -> {
assertAddresses(remote == null && testAddress.isInetSocket() ? proxy.getConnectionLocalAddress() : remote, req.remoteAddress());
assertAddresses(local == null && testAddress.isInetSocket() ? proxy.getConnectionRemoteAddress() : local, req.localAddress());
req.response().end();
complete();
});
startServer(testAddress);
client.request(new RequestOptions().setHost(proxy.getHost()).setPort(proxy.getPort()).setURI(DEFAULT_TEST_URI)).onComplete(onSuccess(req -> {
req.send(onSuccess(event -> complete()));
}));
try {
await();
} finally {
proxy.stop();
}
}
use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.
the class HttpTest method testHAProxyProtocolIdleTimeout.
@Test
public void testHAProxyProtocolIdleTimeout() throws Exception {
HAProxy proxy = new HAProxy(testAddress, Buffer.buffer());
proxy.start(vertx);
server.close();
server = vertx.createHttpServer(createBaseServerOptions().setProxyProtocolTimeout(2).setUseProxyProtocol(true));
server.requestHandler(req -> fail("Should not be called"));
startServer(testAddress);
vertx.createNetClient().connect(proxy.getPort(), proxy.getHost(), res -> {
res.result().closeHandler(event -> testComplete());
});
try {
await();
} finally {
proxy.stop();
}
}
Aggregations