GeezerVison is showing github.com — Honor maxAllocation for brotli in DelegatingDecompressorFrameListener… · netty/netty@46ee86b
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/io/netty/handler/codec/http2 test/java/io/netty/handler/codec/http2
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -196,7 +196,7 @@ protected EmbeddedChannel newContentDecompressor(final ChannelHandlerContext ctx |
196 | 196 | .channelId(channel.id()) |
197 | 197 | .hasDisconnect(channel.metadata().hasDisconnect()) |
198 | 198 | .config(channel.config()) |
199 | | - .handlers(new BrotliDecoder(maxAllocation)) |
| 199 | + .handlers(BrotliDecoder.newDecoderWithMaxAllocation(maxAllocation)) |
200 | 200 | .build(); |
201 | 201 | } |
202 | 202 | if (SNAPPY.contentEqualsIgnoreCase(contentEncoding)) { |
|
Collapse file
Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -275,6 +275,27 @@ public Void call() throws Exception { |
275 | 275 | }); |
276 | 276 | } |
277 | 277 |
|
| 278 | + @ParameterizedTest |
| 279 | + @ValueSource(ints = {0, 10}) |
| 280 | + public void brotliEncodingHonorsMaxAllocation(final int padding) throws Exception { |
| 281 | + // Use a maxAllocation well below the default output buffer size of the BrotliDecoder (64 KiB). |
| 282 | + final byte[] text = new byte[128 * 1024]; |
| 283 | + for (int i = 0; i < text.length; i++) { |
| 284 | + text[i] = (byte) (i % 251); |
| 285 | + } |
| 286 | + maxAllocation = 1024; |
| 287 | + |
| 288 | + testEncodingMessage(padding, text, HttpHeaderValues.BR, new Callable<Void>() { |
| 289 | + @Override |
| 290 | + public Void call() throws Exception { |
| 291 | + awaitServer(); |
| 292 | + assertThat(serverOut.toByteArray()).isEqualTo(text); |
| 293 | + assertThat(maxServerOutBufferSize).isLessThanOrEqualTo(maxAllocation); |
| 294 | + return null; |
| 295 | + } |
| 296 | + }); |
| 297 | + } |
| 298 | + |
278 | 299 | private void testEncodingMessage(int padding, String text, AsciiString compressionAlgorithmName) throws Exception { |
279 | 300 | testEncodingMessage(padding, text, compressionAlgorithmName, new Callable<Void>() { |
280 | 301 | @Override |
|