Source:
public void testTransferCodingGZIPAndChunked() { String requestStr = "POST / HTTP/1.1\r\n" + "Host: example.com\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + "Trailer: My-Trailer\r\n" + "Transfer-Encoding: gzip, chunked\r\n" + "\r\n"; HttpRequestDecoder decoder = new HttpRequestDecoder(); HttpContentDecoder decompressor = new HttpContentDecompressor(); EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor); assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII))); String chunkLength = Integer.toHexString(GZ_HELLO_WORLD.length); assertTrue(channel.writeInbound(Unpooled.copiedBuffer(chunkLength + "\r\n", CharsetUtil.US_ASCII))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer(GZ_HELLO_WORLD))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer("\r\n".getBytes(CharsetUtil.US_ASCII)))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer("0\r\n", CharsetUtil.US_ASCII))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer("My-Trailer: 42\r\n\r\n\r\n", CharsetUtil.US_ASCII))); HttpRequest request = channel.readInbound(); assertTrue(request.decoderResult().isSuccess()); assertTrue(request.headers().containsValue("Transfer-Encoding", "chunked", true)); assertFalse(request.headers().contains("Content-Length")); HttpContent chunk1 = channel.readInbound(); assertTrue(chunk1.decoderResult().isSuccess()); assertEquals(HELLO_WORLD, chunk1.content().toString(CharsetUtil.US_ASCII)); chunk1.release(); LastHttpContent chunk2 = channel.readInbound(); assertTrue(chunk2.decoderResult().isSuccess()); assertEquals("42", chunk2.trailingHeaders().get("My-Trailer")); chunk2.release(); assertFalse(channel.finish()); channel.releaseInbound(); }

Target:
public void testTransferCodingGZIPAndChunked() { String requestStr = "POST / HTTP/1.1\r\n" + "Host: example.com\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + "Trailer: My-Trailer\r\n" + "Transfer-Encoding: gzip, chunked\r\n" + "\r\n"; HttpRequestDecoder decoder = new HttpRequestDecoder(); HttpContentDecoder decompressor = new HttpContentDecompressor(); EmbeddedChannel channel = new EmbeddedChannel(decoder, decompressor); assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII))); String chunkLength = Integer.toHexString(GZ_HELLO_WORLD.length); assertTrue(channel.writeInbound(Unpooled.copiedBuffer(chunkLength + "\r\n", CharsetUtil.US_ASCII))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer(GZ_HELLO_WORLD))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer("\r\n".getBytes(CharsetUtil.US_ASCII)))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer("0\r\n", CharsetUtil.US_ASCII))); assertTrue(channel.writeInbound(Unpooled.copiedBuffer("My-Trailer: 42\r\n\r\n", CharsetUtil.US_ASCII))); HttpRequest request = channel.readInbound(); assertTrue(request.decoderResult().isSuccess()); assertTrue(request.headers().containsValue(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED, true)); assertFalse(request.headers().contains(HttpHeaderNames.CONTENT_LENGTH)); HttpContent chunk1 = channel.readInbound(); assertTrue(chunk1.decoderResult().isSuccess()); assertEquals(HELLO_WORLD, chunk1.content().toString(CharsetUtil.US_ASCII)); chunk1.release(); LastHttpContent chunk2 = channel.readInbound(); assertTrue(chunk2.decoderResult().isSuccess()); assertEquals("42", chunk2.trailingHeaders().get("My-Trailer")); chunk2.release(); assertFalse(channel.finish()); channel.releaseInbound(); }