HAProxyMessageDecoder extends ByteToMessageDecoder { private void fail(final ChannelHandlerContext ctx, String errMsg, Exception e) { finished = true; ctx.close(); HAProxyProtocolException ppex; if (errMsg != null && e != null) { ppex = new HAProxyProtocolException(errMsg, e); } else if (errMsg != null) { ppex = new HAProxyProtocolException(errMsg); } else if (e != null) { ppex = new HAProxyProtocolException(e); } else { ppex = new HAProxyProtocolException(); } throw ppex; } HAProxyMessageDecoder();  HAProxyMessageDecoder(int maxTlvSize); @Override boolean isSingleDecode(); @Override void channelRead(ChannelHandlerContext ctx, Object msg); static ProtocolDetectionResult<HAProxyProtocolVersion> detectProtocol(ByteBuf buffer);  }
@Test public void testCloseOnInvalid() { ChannelFuture closeFuture = ch.closeFuture(); String header = "GET / HTTP/1.1\r\n"; try { ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII)); } catch (HAProxyProtocolException ppex) { } boolean isComplete = closeFuture.awaitUninterruptibly(5000); if (!isComplete || !closeFuture.isDone() || !closeFuture.isSuccess()) { fail("Expected channel close"); } }