forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compression: add brotli compressor and decompressor (envoyproxy#12998)
Commit Message: compression: add brotli compressor and decompressor Additional Description: Add new brotli compression extensions in addition to gzip. Risk Level: Low, no existing functionality is touched Testing: uni tests, manual tests with curl. Docs Changes: updated docs for compression and decompression HTTP filters to refer the new available encoder/decoder. Release Notes: updated current.rst Fixes envoyproxy#4429 The PR adds a new dependency on https://github.com/google/brotli. Here's the current criteria answers: | Criteria | Answer | |---------|---------| | Cloud Native Computing Foundation (CNCF) approved license | MIT | | Dependencies must not substantially increase the binary size unless they are optional | brotli's binary size built with `-c opt` is 752K | | No duplication of existing dependencies | no other dep provides Brotli | | Hosted on a git repository and the archive fetch must directly reference this repository. | https://github.com/google/brotli | | CVE history appears reasonable, no pathological CVE arcs | so far 4 CVEs related to brotli have been registered | | Code review (ideally PRs) before merge | PRs are reviewed before merge | | Security vulnerability process exists, with contact details and reporting/disclosure process | no policy exists, submitted google/brotli#878 | | > 1 contributor responsible for a non-trivial number of commits | 75 contributors | | Tests run in CI | CI set up with AppVeyor and Github actions | | High test coverage (also static/dynamic analysis, fuzzing) | Fuzzers are run in CI | | Envoy can obtain advanced notification of vulnerabilities or of security releases | brotli is registered in CPE | | Do other significant projects have shared fate by using this dependency? | Google Chrome is using the library | | Releases (with release notes) | https://github.com/google/brotli/releases | | Commits/releases in last 90 days | last commit 9 days ago | Signed-off-by: Dmitry Rozhkov <[email protected]>
- Loading branch information
Showing
38 changed files
with
1,397 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
) |
54 changes: 54 additions & 0 deletions
54
api/envoy/extensions/compression/brotli/compressor/v3/brotli.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.compression.brotli.compressor.v3; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.compression.brotli.compressor.v3"; | ||
option java_outer_classname = "BrotliProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Brotli Compressor] | ||
// [#extension: envoy.compression.brotli.compressor] | ||
|
||
// [#next-free-field: 7] | ||
message Brotli { | ||
enum EncoderMode { | ||
DEFAULT = 0; | ||
GENERIC = 1; | ||
TEXT = 2; | ||
FONT = 3; | ||
} | ||
|
||
// Value from 0 to 11 that controls the main compression speed-density lever. | ||
// The higher quality, the slower compression. The default value is 3. | ||
google.protobuf.UInt32Value quality = 1 [(validate.rules).uint32 = {lte: 11}]; | ||
|
||
// A value used to tune encoder for specific input. For more information about modes, | ||
// please refer to brotli manual: https://brotli.org/encode.html#aa6f | ||
// This field will be set to "DEFAULT" if not specified. | ||
EncoderMode encoder_mode = 2 [(validate.rules).enum = {defined_only: true}]; | ||
|
||
// Value from 10 to 24 that represents the base two logarithmic of the compressor's window size. | ||
// Larger window results in better compression at the expense of memory usage. The default is 18. | ||
// For more details about this parameter, please refer to brotli manual: | ||
// https://brotli.org/encode.html#a9a8 | ||
google.protobuf.UInt32Value window_bits = 3 [(validate.rules).uint32 = {lte: 24 gte: 10}]; | ||
|
||
// Value from 16 to 24 that represents the base two logarithmic of the compressor's input block | ||
// size. Larger input block results in better compression at the expense of memory usage. The | ||
// default is 24. For more details about this parameter, please refer to brotli manual: | ||
// https://brotli.org/encode.html#a9a8 | ||
google.protobuf.UInt32Value input_block_bits = 4 [(validate.rules).uint32 = {lte: 24 gte: 16}]; | ||
|
||
// Value for compressor's next output buffer. If not set, defaults to 4096. | ||
google.protobuf.UInt32Value chunk_size = 5 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; | ||
|
||
// If true, disables "literal context modeling" format feature. | ||
// This flag is a "decoding-speed vs compression ratio" trade-off. | ||
bool disable_literal_context_modeling = 6; | ||
} |
9 changes: 9 additions & 0 deletions
9
api/envoy/extensions/compression/brotli/decompressor/v3/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
) |
25 changes: 25 additions & 0 deletions
25
api/envoy/extensions/compression/brotli/decompressor/v3/brotli.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.compression.brotli.decompressor.v3; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.compression.brotli.decompressor.v3"; | ||
option java_outer_classname = "BrotliProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Brotli Decompressor] | ||
// [#extension: envoy.compression.brotli.decompressor] | ||
|
||
message Brotli { | ||
// If true, disables "canny" ring buffer allocation strategy. | ||
// Ring buffer is allocated according to window size, despite the real size of the content. | ||
bool disable_ring_buffer_reallocation = 1; | ||
|
||
// Value for decompressor's next output buffer. If not set, defaults to 4096. | ||
google.protobuf.UInt32Value chunk_size = 2 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ Compression | |
:maxdepth: 2 | ||
|
||
../../extensions/compression/gzip/*/v3/* | ||
../../extensions/compression/brotli/*/v3/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
generated_api_shadow/envoy/extensions/compression/brotli/compressor/v3/BUILD
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
generated_api_shadow/envoy/extensions/compression/brotli/compressor/v3/brotli.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
generated_api_shadow/envoy/extensions/compression/brotli/decompressor/v3/BUILD
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
generated_api_shadow/envoy/extensions/compression/brotli/decompressor/v3/brotli.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_library( | ||
name = "brotli_base_lib", | ||
srcs = ["base.cc"], | ||
hdrs = ["base.h"], | ||
deps = [ | ||
"//source/common/buffer:buffer_lib", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "extensions/compression/brotli/common/base.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Compression { | ||
namespace Brotli { | ||
namespace Common { | ||
|
||
BrotliContext::BrotliContext(const uint32_t chunk_size) | ||
: chunk_size_{chunk_size}, chunk_ptr_{std::make_unique<uint8_t[]>(chunk_size)}, next_in_{}, | ||
next_out_{chunk_ptr_.get()}, avail_in_{0}, avail_out_{chunk_size} {} | ||
|
||
void BrotliContext::updateOutput(Buffer::Instance& output_buffer) { | ||
if (avail_out_ == 0) { | ||
output_buffer.add(static_cast<void*>(chunk_ptr_.get()), chunk_size_); | ||
resetOut(); | ||
} | ||
} | ||
|
||
void BrotliContext::finalizeOutput(Buffer::Instance& output_buffer) { | ||
const size_t n_output = chunk_size_ - avail_out_; | ||
if (n_output > 0) { | ||
output_buffer.add(static_cast<void*>(chunk_ptr_.get()), n_output); | ||
} | ||
} | ||
|
||
void BrotliContext::resetOut() { | ||
avail_out_ = chunk_size_; | ||
next_out_ = chunk_ptr_.get(); | ||
} | ||
|
||
} // namespace Common | ||
} // namespace Brotli | ||
} // namespace Compression | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.