Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip filter: allow setting zlib compressor's chunk size #10508

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/envoy/config/filter/http/gzip/v2/gzip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// Gzip :ref:`configuration overview <config_http_filters_gzip>`.
// [#extension: envoy.filters.http.gzip]

// [#next-free-field: 11]
// [#next-free-field: 12]
message Gzip {
enum CompressionStrategy {
DEFAULT = 0;
Expand Down Expand Up @@ -95,4 +95,8 @@ message Gzip {
// the fields `content_length`, `content_type`, `disable_on_etag_header` and
// `remove_accept_encoding_header` are ignored.
compressor.v2.Compressor compressor = 10;

// Value for Zlib's next output buffer. If not set, defaults to 4096.
// See https://www.zlib.net/manual.html.
google.protobuf.UInt64Value chunk_size = 11 [(validate.rules).uint64 = {lte: 65536 gte: 4096}];
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 5 additions & 1 deletion api/envoy/extensions/filters/http/gzip/v3/gzip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ option (udpa.annotations.file_status).package_version_status = NEXT_MAJOR_VERSIO
// Gzip :ref:`configuration overview <config_http_filters_gzip>`.
// [#extension: envoy.filters.http.gzip]

// [#next-free-field: 11]
// [#next-free-field: 12]
message Gzip {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.http.gzip.v2.Gzip";
Expand Down Expand Up @@ -76,4 +76,8 @@ message Gzip {
// the fields `content_length`, `content_type`, `disable_on_etag_header` and
// `remove_accept_encoding_header` are ignored.
compressor.v3.Compressor compressor = 10;

// Value for Zlib's next output buffer. If not set, defaults to 4096.
// See https://www.zlib.net/manual.html.
google.protobuf.UInt64Value chunk_size = 11 [(validate.rules).uint64 = {lte: 65536 gte: 4096}];
}
5 changes: 3 additions & 2 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Version history
* aws_request_signing: a few fixes so that it works with S3.
* buffer: force copy when appending small slices to OwnedImpl buffer to avoid fragmentation.
* config: use type URL to select an extension whenever the config type URL (or its previous versions) uniquely identify a typed extension, see :ref:`extension configuration <config_overview_extension_configuration>`.
* grpc-json: added support for building HTTP request into
`google.api.HttpBody <https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto>`_.
* config: added stat :ref:`update_time <config_cluster_manager_cds>`.
* datasource: added retry policy for remote async data source.
* dns: the STRICT_DNS cluster now only resolves to 0 hosts if DNS resolution successfully returns 0 hosts.
Expand All @@ -28,6 +26,9 @@ Version history
* ext_authz: disabled the use of lowercase string matcher for headers matching in HTTP-based `ext_authz`.
Can be reverted temporarily by setting runtime feature `envoy.reloadable_features.ext_authz_http_service_enable_case_sensitive_string_matcher` to false.
* fault: added support for controlling abort faults with :ref:`HTTP header fault configuration <config_http_filters_fault_injection_http_header>` to the HTTP fault filter.
* grpc-json: added support for building HTTP request into
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
`google.api.HttpBody <https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto>`_.
* gzip filter: added option to set zlib's next output buffer.
* http: added HTTP/1.1 flood protection. Can be temporarily disabled using the runtime feature `envoy.reloadable_features.http1_flood_protection`
* http: fixing a bug in HTTP/1.0 responses where Connection: keep-alive was not appended for connections which were kept alive.
* http: fixed a bug that could send extra METADATA frames and underflow memory when encoding METADATA frames on a connection that was dispatching data.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions source/extensions/filters/http/gzip/gzip_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ GzipFilterConfig::GzipFilterConfig(const envoy::extensions::filters::http::gzip:
compression_level_(compressionLevelEnum(gzip.compression_level())),
compression_strategy_(compressionStrategyEnum(gzip.compression_strategy())),
memory_level_(memoryLevelUint(gzip.memory_level().value())),
window_bits_(windowBitsUint(gzip.window_bits().value())) {}
window_bits_(windowBitsUint(gzip.window_bits().value())),
chunk_size_(gzip.chunk_size().value() > 0 ? gzip.chunk_size().value() : 4096) {}
rgs1 marked this conversation as resolved.
Show resolved Hide resolved
rgs1 marked this conversation as resolved.
Show resolved Hide resolved

std::unique_ptr<Compressor::Compressor> GzipFilterConfig::makeCompressor() {
auto compressor = std::make_unique<Compressor::ZlibCompressorImpl>();
auto compressor = std::make_unique<Compressor::ZlibCompressorImpl>(chunk_size_);
compressor->init(compressionLevel(), compressionStrategy(), windowBits(), memoryLevel());
return compressor;
}
Expand Down
6 changes: 4 additions & 2 deletions source/extensions/filters/http/gzip/gzip_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GzipFilterConfig : public Common::Compressors::CompressorFilterConfig {

uint64_t memoryLevel() const { return memory_level_; }
uint64_t windowBits() const { return window_bits_; }
uint64_t chunkSize() const { return chunk_size_; }

private:
static Compressor::ZlibCompressorImpl::CompressionLevel compressionLevelEnum(
Expand All @@ -48,8 +49,9 @@ class GzipFilterConfig : public Common::Compressors::CompressorFilterConfig {
Compressor::ZlibCompressorImpl::CompressionLevel compression_level_;
Compressor::ZlibCompressorImpl::CompressionStrategy compression_strategy_;

int32_t memory_level_;
int32_t window_bits_;
const int32_t memory_level_;
const int32_t window_bits_;
const uint64_t chunk_size_;
};

} // namespace Gzip
Expand Down
15 changes: 15 additions & 0 deletions test/extensions/filters/http/gzip/gzip_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,21 @@ TEST(GzipFilterConfigTest, DEPRECATED_FEATURE_TEST(DeprecatedExtensionFilterName
deprecated_name));
}

// Test setting zlib's chunk size.
TEST_F(GzipFilterTest, ChunkSize) {
// Default
setUpFilter("{}");
EXPECT_EQ(config_->chunkSize(), 4096);

// Override
setUpFilter(R"EOF(
{
"chunk_size": 8192
}
)EOF");
EXPECT_EQ(config_->chunkSize(), 8192);
}

} // namespace Gzip
} // namespace HttpFilters
} // namespace Extensions
Expand Down