Repository navigation
Introduce BrotliEncoder - #11256
Introduce BrotliEncoder#11256
Conversation
0adae1b to
faa0621
Compare
Fix failing test Revert IDE formatting Revert IDE formatting fixes fix test Revert more
|
@hyperxpro Is brotli compression really supposed to be performed on the fly? From what I've experienced so far, compression seems to be really slow and best performed once and for all for static content, then cached. |
|
@slandelle I agree with your point but Brotli compression speed cost is compensated by the compression ratio. So yeah, we can have it. |
idelpivnitskiy
left a comment
There was a problem hiding this comment.
Thank you for the PR @hyperxpro!
+1 for adding tests. For BrotliEncoder it's enough to add a subclass of AbstractEncoderTest. See LzfEncoderTest as an example. But we also need tests for new features of HttpContentCompressor and CompressorHttp2ConnectionEncoder.
Please, also add reference to brotli4j in NOTICE.txt file, and add LICENSE.brotli4j.txt file in license folder. We forgot to do that when we added decoder.
|
I will add tests once you guys are okay with new commits. |
idelpivnitskiy
left a comment
There was a problem hiding this comment.
BrotliEncoder and its test class LGTM! I will leave HTTP-related classes for others to review as I don't have much context on it.
Please, also add tests for HTTP with "br" compression to cover BrotliContentCompressor and CompressorHttp2ConnectionEncoder.
@normanmaurer Can you help? The test is same as |
@hyperxpro @Override
protected EmbeddedChannel createChannel() {
return new EmbeddedChannel(new BrotliEncoder());
} |
|
It's in the last call. The compression bug is fixed (by using TEXT mode). |
|
@hyperxpro PTAL ... I think moving the options make more sense |
The API looks amazing. Thanks for the change. :) |
|
@hyperxpro thanks a lot! |
|
Thanks a lot to everyone who participated in this PR and gave their feedback. :) |
Motivation: Currently, Netty only has BrotliDecoder which can decode Brotli encoded data. However, BrotliEncoder is missing which will encode normal data to Brotli encoded data. Modification: Added BrotliEncoder and CompressionOption Result: Fixes #6899. Co-authored-by: Norman Maurer <[email protected]>
| } | ||
|
|
||
| /** | ||
| * @see BrotliOptions#DEFAULT |
There was a problem hiding this comment.
This, as well as other member references in this class's Javadoc, won't be linked properly in generated Javadoc because they are not public. We need to write a proper first sentence, such as:
* Returns the {@link BrotliOptions} with the default compression settings.
There was a problem hiding this comment.
I will do it as I've upcoming PR to enable Brotli tests on Windows.
|
Thanks a lot for your hard work, @hyperxpro! Looking great indeed. Too bad we're not at Java 8 yet, though 😅 |
…11482) Motivation: In #11256, We introduced `Iterable` as a parameter but later in review, it was removed. But we forgot to change `compressionOptionsIterable` to just `compressionOptions`. Modification: Changed `compressionOptionsIterable` to `compressionOptions`. Result: Correct ObjectUtil message
…11482) Motivation: In #11256, We introduced `Iterable` as a parameter but later in review, it was removed. But we forgot to change `compressionOptionsIterable` to just `compressionOptions`. Modification: Changed `compressionOptionsIterable` to `compressionOptions`. Result: Correct ObjectUtil message
Motivation: Currently, Netty only has BrotliDecoder which can decode Brotli encoded data. However, BrotliEncoder is missing which will encode normal data to Brotli encoded data. Modification: Added BrotliEncoder and CompressionOption Result: Fixes netty#6899. Co-authored-by: Norman Maurer <[email protected]>
…etty#11482) Motivation: In netty#11256, We introduced `Iterable` as a parameter but later in review, it was removed. But we forgot to change `compressionOptionsIterable` to just `compressionOptions`. Modification: Changed `compressionOptionsIterable` to `compressionOptions`. Result: Correct ObjectUtil message
…` license ### What changes were proposed in this pull request? This PR aims to update `NOTICE-binary` with `Netty` 4.2.7 license. - https://github.com/netty/netty/blob/netty-4.2.7.Final/NOTICE.txt ### Why are the changes needed? It seems that we updated `Netty Notice` at Apache Spark `3.0.0-preview` with `Netty 4.1.30.Final`. - #25544 Since there are many changes like the following, we need to update it by simply copying and pasting. - Netty 4.1.38.Final - netty/netty#9344 - Netty 4.1.44.Final - netty/netty#9161 - Netty 4.1.54.Final - netty/netty#10773 - Netty 4.1.66.Final - netty/netty#11256 - netty/netty#11437 - Netty 4.1.108.Final - netty/netty#13864 - Netty 4.2.1.Final - netty/netty#14979 - Netty 4.2.7.Final - netty/netty#15658 Additionally, I also double-checked newly added transitive license through ASF [LEGAL-700](https://issues.apache.org/jira/browse/LEGAL-700). We are good to go. - **Apple Public Source License 2.0** - https://spdx.org/licenses/APSL-2.0.html ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Manual review. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #53335 from dongjoon-hyun/SPARK-54602. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
…` license ### What changes were proposed in this pull request? This PR aims to update `NOTICE-binary` with `Netty` 4.2.7 license. - https://github.com/netty/netty/blob/netty-4.2.7.Final/NOTICE.txt ### Why are the changes needed? It seems that we updated `Netty Notice` at Apache Spark `3.0.0-preview` with `Netty 4.1.30.Final`. - #25544 Since there are many changes like the following, we need to update it by simply copying and pasting. - Netty 4.1.38.Final - netty/netty#9344 - Netty 4.1.44.Final - netty/netty#9161 - Netty 4.1.54.Final - netty/netty#10773 - Netty 4.1.66.Final - netty/netty#11256 - netty/netty#11437 - Netty 4.1.108.Final - netty/netty#13864 - Netty 4.2.1.Final - netty/netty#14979 - Netty 4.2.7.Final - netty/netty#15658 Additionally, I also double-checked newly added transitive license through ASF [LEGAL-700](https://issues.apache.org/jira/browse/LEGAL-700). We are good to go. - **Apple Public Source License 2.0** - https://spdx.org/licenses/APSL-2.0.html ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Manual review. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #53335 from dongjoon-hyun/SPARK-54602. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]> (cherry picked from commit 191ce4c) Signed-off-by: Dongjoon Hyun <[email protected]>
#17726) Motivation: `HttpContentCompressor.determineEncoding(...)` parses the qvalue of every coding in `Accept-Encoding` correctly, but then only compares each coding with the next one in the list `br, zstd, snappy, gzip, deflate` (`brQ >= zstdQ`, `zstdQ >= snappyQ`, ...). That pairwise rule was right when only gzip and deflate existed (`determineWrapper(...)`), but with five codings it picks a coding the client ranked lower, or did not accept at all: | `Accept-Encoding` | configured | selected now | expected | |---|---|---|---| | `br;q=0, gzip` | default, Brotli on the class path | `br` | `gzip` | | `gzip, br;q=0` | default, Brotli on the class path | `br` | `gzip` | | `zstd;q=0, gzip` | default, zstd-jni on the class path | `zstd` | `gzip` | | `snappy;q=0, deflate` | default | `snappy` | `deflate` | | `br;q=0, zstd;q=0, snappy;q=0, gzip;q=0, deflate` | default, Brotli on the class path | `br` | `deflate` | | `br;q=0.1, gzip` | default, Brotli on the class path | `br` | `gzip` | [RFC 9110, Section 12.4.2](https://www.rfc-editor.org/rfc/rfc9110#section-12.4.2): "a value of 0 means "not acceptable"", and [Section 12.5.3](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.3): a listed content coding is acceptable "unless it is accompanied by a qvalue of 0". A client that sends `br;q=0` (for example because it cannot decode Brotli) gets a Brotli body it cannot decode. The pairwise comparisons came with the additions of br (#11256), zstd (#11470) and snappy (#13529); the existing tests only cover single codings and equal qvalues. Modification: - Select the configured coding with the highest qvalue above 0. If qvalues are equal, keep the existing order `br, zstd, snappy, gzip, deflate` (so `"gzip, br"` still gives `br`). The `*` handling and the parsing are unchanged. - Add `testDetermineEncodingHonoursQValues` (gzip, deflate and snappy configured, runs everywhere) and `testDetermineEncodingHonoursQValuesBrotli` (`@EnabledIf("isBrotliAvailable")`) as `@ParameterizedTest`s. - Update `HttpContentCompressorOptionsTest`: `"br; q=0, deflate"` (and the same for zstd and snappy) now selects `deflate`, as the listed coding has qvalue 0. Result: The compressor no longer uses a content coding the client marked as not acceptable, and prefers the coding with the higher qvalue. Requests whose explicitly listed codings have equal qvalues, and requests that only use `*`, give the same result as before. --------- Co-authored-by: Norman Maurer <[email protected]>
…content encoding (#18285) Auto-port of #17726 to 5.0 Cherry-picked commit: 5a638e4 --- Motivation: `HttpContentCompressor.determineEncoding(...)` parses the qvalue of every coding in `Accept-Encoding` correctly, but then only compares each coding with the next one in the list `br, zstd, snappy, gzip, deflate` (`brQ >= zstdQ`, `zstdQ >= snappyQ`, ...). That pairwise rule was right when only gzip and deflate existed (`determineWrapper(...)`), but with five codings it picks a coding the client ranked lower, or did not accept at all: | `Accept-Encoding` | configured | selected now | expected | |---|---|---|---| | `br;q=0, gzip` | default, Brotli on the class path | `br` | `gzip` | | `gzip, br;q=0` | default, Brotli on the class path | `br` | `gzip` | | `zstd;q=0, gzip` | default, zstd-jni on the class path | `zstd` | `gzip` | | `snappy;q=0, deflate` | default | `snappy` | `deflate` | | `br;q=0, zstd;q=0, snappy;q=0, gzip;q=0, deflate` | default, Brotli on the class path | `br` | `deflate` | | `br;q=0.1, gzip` | default, Brotli on the class path | `br` | `gzip` | [RFC 9110, Section 12.4.2](https://www.rfc-editor.org/rfc/rfc9110#section-12.4.2): "a value of 0 means "not acceptable"", and [Section 12.5.3](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.3): a listed content coding is acceptable "unless it is accompanied by a qvalue of 0". A client that sends `br;q=0` (for example because it cannot decode Brotli) gets a Brotli body it cannot decode. The pairwise comparisons came with the additions of br (#11256), zstd (#11470) and snappy (#13529); the existing tests only cover single codings and equal qvalues. Modification: - Select the configured coding with the highest qvalue above 0. If qvalues are equal, keep the existing order `br, zstd, snappy, gzip, deflate` (so `"gzip, br"` still gives `br`). The `*` handling and the parsing are unchanged. - Add `testDetermineEncodingHonoursQValues` (gzip, deflate and snappy configured, runs everywhere) and `testDetermineEncodingHonoursQValuesBrotli` (`@EnabledIf("isBrotliAvailable")`) as `@ParameterizedTest`s. - Update `HttpContentCompressorOptionsTest`: `"br; q=0, deflate"` (and the same for zstd and snappy) now selects `deflate`, as the listed coding has qvalue 0. Result: The compressor no longer uses a content coding the client marked as not acceptable, and prefers the coding with the higher qvalue. Requests whose explicitly listed codings have equal qvalues, and requests that only use `*`, give the same result as before. - `HttpContentCompressorTest`, `HttpContentEncoderTest`, `HttpContentDecompressorTest` pass (63 tests), and `HttpContentCompressorOptionsTest` passes (4). Without the change to `HttpContentCompressor`, 7 of the 13 new cases fail; the others pass both ways. - Checkstyle and revapi pass. The selection was also modelled in Lean 4 against the RFC 9110 rule: for every combination of qvalues from {absent, 0, 0.5, 1} for the five codings and `*`, and every subset of configured codings with qvalues from {absent, 0, 1}, the new selection only returns an acceptable coding with the highest qvalue, and it returns the same coding as before whenever the current result already satisfied that. The change was prepared with Claude Code (Claude Opus 5.5), and the commit has a `Co-Authored-By` trailer. _Prepared with Claude Code on behalf of allthingssecurity._ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: allthingssecurity <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
…ent encoding (netty/netty#17726) Motivation: `HttpContentCompressor.determineEncoding(...)` parses the qvalue of every coding in `Accept-Encoding` correctly, but then only compares each coding with the next one in the list `br, zstd, snappy, gzip, deflate` (`brQ >= zstdQ`, `zstdQ >= snappyQ`, ...). That pairwise rule was right when only gzip and deflate existed (`determineWrapper(...)`), but with five codings it picks a coding the client ranked lower, or did not accept at all: | `Accept-Encoding` | configured | selected now | expected | |---|---|---|---| | `br;q=0, gzip` | default, Brotli on the class path | `br` | `gzip` | | `gzip, br;q=0` | default, Brotli on the class path | `br` | `gzip` | | `zstd;q=0, gzip` | default, zstd-jni on the class path | `zstd` | `gzip` | | `snappy;q=0, deflate` | default | `snappy` | `deflate` | | `br;q=0, zstd;q=0, snappy;q=0, gzip;q=0, deflate` | default, Brotli on the class path | `br` | `deflate` | | `br;q=0.1, gzip` | default, Brotli on the class path | `br` | `gzip` | [RFC 9110, Section 12.4.2](https://www.rfc-editor.org/rfc/rfc9110#section-12.4.2): "a value of 0 means "not acceptable"", and [Section 12.5.3](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.3): a listed content coding is acceptable "unless it is accompanied by a qvalue of 0". A client that sends `br;q=0` (for example because it cannot decode Brotli) gets a Brotli body it cannot decode. The pairwise comparisons came with the additions of br (netty/netty#11256), zstd (netty/netty#11470) and snappy (netty/netty#13529); the existing tests only cover single codings and equal qvalues. Modification: - Select the configured coding with the highest qvalue above 0. If qvalues are equal, keep the existing order `br, zstd, snappy, gzip, deflate` (so `"gzip, br"` still gives `br`). The `*` handling and the parsing are unchanged. - Add `testDetermineEncodingHonoursQValues` (gzip, deflate and snappy configured, runs everywhere) and `testDetermineEncodingHonoursQValuesBrotli` (`@EnabledIf("isBrotliAvailable")`) as `@ParameterizedTest`s. - Update `HttpContentCompressorOptionsTest`: `"br; q=0, deflate"` (and the same for zstd and snappy) now selects `deflate`, as the listed coding has qvalue 0. Result: The compressor no longer uses a content coding the client marked as not acceptable, and prefers the coding with the higher qvalue. Requests whose explicitly listed codings have equal qvalues, and requests that only use `*`, give the same result as before. --------- Co-authored-by: Norman Maurer <[email protected]> Upstream-Commit: netty/netty@5a638e4
Motivation:
Currently, Netty only has BrotliDecoder which can decode Brotli encoded data. However, BrotliEncoder is missing which will encode normal data to Brotli encoded data.
Modification:
Added BrotliEncoder
Result:
Fixes #6899.