use of io.netty.handler.codec.haproxy.HAProxyMessageDecoder in project zuul by Netflix.
the class HAProxyMessageChannelHandlerTest method setClientDestPortForHAPM.
@Test
public void setClientDestPortForHAPM() {
EmbeddedChannel channel = new EmbeddedChannel();
// This is normally done by Server.
channel.attr(Server.CONN_DIMENSIONS).set(Attrs.newInstance());
// This is to emulate `ElbProxyProtocolChannelHandler`
channel.pipeline().addLast(HAProxyMessageDecoder.class.getSimpleName(), new HAProxyMessageDecoder()).addLast(HAProxyMessageChannelHandler.class.getSimpleName(), new HAProxyMessageChannelHandler());
ByteBuf buf = Unpooled.wrappedBuffer("PROXY TCP4 192.168.0.1 124.123.111.111 10008 443\r\n".getBytes(StandardCharsets.US_ASCII));
channel.writeInbound(buf);
Object result = channel.readInbound();
assertNull(result);
InetSocketAddress destAddress = channel.attr(SourceAddressChannelHandler.ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS).get();
InetSocketAddress srcAddress = (InetSocketAddress) channel.attr(SourceAddressChannelHandler.ATTR_REMOTE_ADDR).get();
assertEquals("124.123.111.111", destAddress.getHostString());
assertEquals(443, destAddress.getPort());
assertEquals("192.168.0.1", srcAddress.getHostString());
assertEquals(10008, srcAddress.getPort());
Attrs attrs = channel.attr(Server.CONN_DIMENSIONS).get();
Integer port = HAProxyMessageChannelHandler.HAPM_DEST_PORT.get(attrs);
assertEquals(443, port.intValue());
String sourceIpVersion = HAProxyMessageChannelHandler.HAPM_SRC_IP_VERSION.get(attrs);
assertEquals("v4", sourceIpVersion);
String destIpVersion = HAProxyMessageChannelHandler.HAPM_DEST_IP_VERSION.get(attrs);
assertEquals("v4", destIpVersion);
}
use of io.netty.handler.codec.haproxy.HAProxyMessageDecoder in project vert.x by eclipse.
the class HttpServerWorker method handle.
@Override
public void handle(Channel ch) {
if (HAProxyMessageCompletionHandler.canUseProxyProtocol(options.isUseProxyProtocol())) {
IdleStateHandler idle;
io.netty.util.concurrent.Promise<Channel> p = ch.eventLoop().newPromise();
ch.pipeline().addLast(new HAProxyMessageDecoder());
if (options.getProxyProtocolTimeout() > 0) {
ch.pipeline().addLast("idle", idle = new IdleStateHandler(0, 0, options.getProxyProtocolTimeout(), options.getProxyProtocolTimeoutUnit()));
} else {
idle = null;
}
ch.pipeline().addLast(new HAProxyMessageCompletionHandler(p));
p.addListener((GenericFutureListener<Future<Channel>>) future -> {
if (future.isSuccess()) {
if (idle != null) {
ch.pipeline().remove(idle);
}
configurePipeline(future.getNow());
} else {
handleException(future.cause());
}
});
} else {
configurePipeline(ch);
}
}
Aggregations