HttpContentDecompressorTest Class — netty Architecture
Architecture documentation for the HttpContentDecompressorTest class in HttpContentDecompressorTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD ad239479_d432_6bb8_104c_16b5ed7eb774["HttpContentDecompressorTest"] 5bcb0483_87ec_e418_270b_d7f960c32109["HttpContentDecompressorTest.java"] ad239479_d432_6bb8_104c_16b5ed7eb774 -->|defined in| 5bcb0483_87ec_e418_270b_d7f960c32109 bf87b63e_4adc_26e5_12ee_55244a091126["testInvokeReadWhenNotProduceMessage()"] ad239479_d432_6bb8_104c_16b5ed7eb774 -->|method| bf87b63e_4adc_26e5_12ee_55244a091126 44fa541c_7af1_7519_3ba0_17999aef930b["encodings()"] ad239479_d432_6bb8_104c_16b5ed7eb774 -->|method| 44fa541c_7af1_7519_3ba0_17999aef930b 0afab2e6_76f5_24bb_602b_64872d230720["testZipBomb()"] ad239479_d432_6bb8_104c_16b5ed7eb774 -->|method| 0afab2e6_76f5_24bb_602b_64872d230720
Relationship Graph
Source Code
codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java lines 41–173
public class HttpContentDecompressorTest {
// See https://github.com/netty/netty/issues/8915.
@Test
public void testInvokeReadWhenNotProduceMessage() {
final AtomicInteger readCalled = new AtomicInteger();
EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void read(ChannelHandlerContext ctx) {
readCalled.incrementAndGet();
ctx.read();
}
}, new HttpContentDecompressor(0), new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ctx.fireChannelRead(msg);
ctx.read();
}
});
channel.config().setAutoRead(false);
readCalled.set(0);
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers().set(HttpHeaderNames.CONTENT_ENCODING, "gzip");
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json;charset=UTF-8");
response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
assertTrue(channel.writeInbound(response));
// we triggered read explicitly
assertEquals(1, readCalled.get());
assertTrue(channel.readInbound() instanceof HttpResponse);
assertFalse(channel.writeInbound(new DefaultHttpContent(Unpooled.EMPTY_BUFFER)));
// read was triggered by the HttpContentDecompressor itself as it did not produce any message to the next
// inbound handler.
assertEquals(2, readCalled.get());
assertFalse(channel.finishAndReleaseAll());
}
static String[] encodings() {
List<String> encodings = new ArrayList<>();
encodings.add("gzip");
encodings.add("deflate");
if (Brotli.isAvailable()) {
encodings.add("br");
}
if (Zstd.isAvailable()) {
encodings.add("zstd");
}
encodings.add("snappy");
return encodings.toArray(new String[0]);
}
@ParameterizedTest
@MethodSource("encodings")
@DisabledForSlowLeakDetection
public void testZipBomb(String encoding) {
int chunkSize = 1024 * 1024;
int numberOfChunks = 256;
int memoryLimit = chunkSize * 128;
EmbeddedChannel compressionChannel = new EmbeddedChannel(new HttpContentCompressor());
DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, encoding);
compressionChannel.writeInbound(req);
DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
compressionChannel.writeOutbound(response);
for (int i = 0; i < numberOfChunks; i++) {
ByteBuf buffer = compressionChannel.alloc().buffer(chunkSize);
buffer.writeZero(chunkSize);
compressionChannel.writeOutbound(new DefaultHttpContent(buffer));
}
compressionChannel.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
compressionChannel.finish();
Source
Frequently Asked Questions
What is the HttpContentDecompressorTest class?
HttpContentDecompressorTest is a class in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java.
Where is HttpContentDecompressorTest defined?
HttpContentDecompressorTest is defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java at line 41.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free