GeezerVison is showing github.com — Auto-port 5.0: Honor maxAllocation for brotli in DelegatingDecompress… · netty/netty@1d30c7a
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 |
|---|
@@ -197,7 +197,7 @@ protected EmbeddedChannel newContentDecompressor(final ChannelHandlerContext ctx |
197 | 197 | return EmbeddedChannel.builder() |
198 | 198 | .channelId(channel.id()) |
199 | 199 | .config(channel.config()) |
200 | | - .handlers(new BrotliDecoder(maxAllocation)) |
| 200 | + .handlers(BrotliDecoder.newDecoderWithMaxAllocation(maxAllocation)) |
201 | 201 | .build(); |
202 | 202 | } |
203 | 203 | 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 |
|---|
@@ -274,6 +274,27 @@ public Void call() throws Exception { |
274 | 274 | }); |
275 | 275 | } |
276 | 276 |
|
| 277 | + @ParameterizedTest |
| 278 | + @ValueSource(ints = {0, 10}) |
| 279 | + public void brotliEncodingHonorsMaxAllocation(final int padding) throws Exception { |
| 280 | + // Use a maxAllocation well below the default output buffer size of the BrotliDecoder (64 KiB). |
| 281 | + final byte[] text = new byte[128 * 1024]; |
| 282 | + for (int i = 0; i < text.length; i++) { |
| 283 | + text[i] = (byte) (i % 251); |
| 284 | + } |
| 285 | + maxAllocation = 1024; |
| 286 | + |
| 287 | + testEncodingMessage(padding, text, HttpHeaderValues.BR, new Callable<Void>() { |
| 288 | + @Override |
| 289 | + public Void call() throws Exception { |
| 290 | + awaitServer(); |
| 291 | + assertThat(serverOut.toByteArray()).isEqualTo(text); |
| 292 | + assertThat(maxServerOutBufferSize).isLessThanOrEqualTo(maxAllocation); |
| 293 | + return null; |
| 294 | + } |
| 295 | + }); |
| 296 | + } |
| 297 | + |
277 | 298 | private void testEncodingMessage(int padding, String text, AsciiString compressionAlgorithmName) throws Exception { |
278 | 299 | testEncodingMessage(padding, text, compressionAlgorithmName, new Callable<Void>() { |
279 | 300 | @Override |
|