Skip to content

Commit

Permalink
gzip: make use of generalized compression filter (#10306)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
  • Loading branch information
rojkov authored Mar 10, 2020
1 parent 5a3542c commit c85bf32
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 820 deletions.
5 changes: 4 additions & 1 deletion api/envoy/config/filter/http/gzip/v2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ 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"],
deps = [
"//envoy/config/filter/http/compressor/v2:pkg",
"@com_github_cncf_udpa//udpa/annotations:pkg",
],
)
29 changes: 24 additions & 5 deletions api/envoy/config/filter/http/gzip/v2/gzip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package envoy.config.filter.http.gzip.v2;

import "envoy/config/filter/http/compressor/v2/compressor.proto";

import "google/protobuf/wrappers.proto";

import "udpa/annotations/migrate.proto";
Expand All @@ -16,7 +18,7 @@ option (udpa.annotations.file_migrate).move_to_package = "envoy.extensions.filte
// Gzip :ref:`configuration overview <config_http_filters_gzip>`.
// [#extension: envoy.filters.http.gzip]

// [#next-free-field: 10]
// [#next-free-field: 11]
message Gzip {
enum CompressionStrategy {
DEFAULT = 0;
Expand All @@ -38,7 +40,10 @@ message Gzip {
google.protobuf.UInt32Value memory_level = 1 [(validate.rules).uint32 = {lte: 9 gte: 1}];

// Minimum response length, in bytes, which will trigger compression. The default value is 30.
google.protobuf.UInt32Value content_length = 2 [(validate.rules).uint32 = {gte: 30}];
// .. attention:
//
// **This field is deprecated**. Set the `compressor` field instead.
google.protobuf.UInt32Value content_length = 2 [deprecated = true];

// A value used for selecting the zlib compression level. This setting will affect speed and
// amount of compression applied to the content. "BEST" provides higher compression at the cost of
Expand All @@ -59,19 +64,33 @@ message Gzip {
// application/json, text/html, etc. When this field is not defined, compression will be applied
// to the following mime-types: "application/javascript", "application/json",
// "application/xhtml+xml", "image/svg+xml", "text/css", "text/html", "text/plain", "text/xml".
repeated string content_type = 6 [(validate.rules).repeated = {max_items: 50}];
// .. attention:
//
// **This field is deprecated**. Set the `compressor` field instead.
repeated string content_type = 6 [deprecated = true];

// If true, disables compression when the response contains an etag header. When it is false, the
// filter will preserve weak etags and remove the ones that require strong validation.
bool disable_on_etag_header = 7;
// .. attention:
//
// **This field is deprecated**. Set the `compressor` field instead.
bool disable_on_etag_header = 7 [deprecated = true];

// If true, removes accept-encoding from the request headers before dispatching it to the upstream
// so that responses do not get compressed before reaching the filter.
bool remove_accept_encoding_header = 8;
// .. attention:
//
// **This field is deprecated**. Set the `compressor` field instead.
bool remove_accept_encoding_header = 8 [deprecated = true];

// Value from 9 to 15 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 12
// which will produce a 4096 bytes window. For more details about this parameter, please refer to
// zlib manual > deflateInit2.
google.protobuf.UInt32Value window_bits = 9 [(validate.rules).uint32 = {lte: 15 gte: 9}];

// Set of configuration parameters common for all compression filters. If this field is set then
// the fields `content_length`, `content_type`, `disable_on_etag_header` and
// `remove_accept_encoding_header` are ignored.
compressor.v2.Compressor compressor = 10;
}
1 change: 1 addition & 0 deletions api/envoy/extensions/filters/http/gzip/v3/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ licenses(["notice"]) # Apache 2
api_proto_package(
deps = [
"//envoy/config/filter/http/gzip/v2:pkg",
"//envoy/extensions/filters/http/compressor/v3:pkg",
"@com_github_cncf_udpa//udpa/annotations:pkg",
],
)
31 changes: 13 additions & 18 deletions api/envoy/extensions/filters/http/gzip/v3/gzip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package envoy.extensions.filters.http.gzip.v3;

import "envoy/extensions/filters/http/compressor/v3/compressor.proto";

import "google/protobuf/wrappers.proto";

import "udpa/annotations/versioning.proto";
Expand All @@ -16,7 +18,7 @@ option java_multiple_files = true;
// Gzip :ref:`configuration overview <config_http_filters_gzip>`.
// [#extension: envoy.filters.http.gzip]

// [#next-free-field: 10]
// [#next-free-field: 11]
message Gzip {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.http.gzip.v2.Gzip";
Expand All @@ -39,13 +41,15 @@ message Gzip {
}
}

reserved 2, 6, 7, 8;

reserved "content_length", "content_type", "disable_on_etag_header",
"remove_accept_encoding_header";

// Value from 1 to 9 that controls the amount of internal memory used by zlib. Higher values
// use more memory, but are faster and produce better compression results. The default value is 5.
google.protobuf.UInt32Value memory_level = 1 [(validate.rules).uint32 = {lte: 9 gte: 1}];

// Minimum response length, in bytes, which will trigger compression. The default value is 30.
google.protobuf.UInt32Value content_length = 2 [(validate.rules).uint32 = {gte: 30}];

// A value used for selecting the zlib compression level. This setting will affect speed and
// amount of compression applied to the content. "BEST" provides higher compression at the cost of
// higher latency, "SPEED" provides lower compression with minimum impact on response time.
Expand All @@ -61,23 +65,14 @@ message Gzip {
// refer to zlib manual.
CompressionStrategy compression_strategy = 4 [(validate.rules).enum = {defined_only: true}];

// Set of strings that allows specifying which mime-types yield compression; e.g.,
// application/json, text/html, etc. When this field is not defined, compression will be applied
// to the following mime-types: "application/javascript", "application/json",
// "application/xhtml+xml", "image/svg+xml", "text/css", "text/html", "text/plain", "text/xml".
repeated string content_type = 6 [(validate.rules).repeated = {max_items: 50}];

// If true, disables compression when the response contains an etag header. When it is false, the
// filter will preserve weak etags and remove the ones that require strong validation.
bool disable_on_etag_header = 7;

// If true, removes accept-encoding from the request headers before dispatching it to the upstream
// so that responses do not get compressed before reaching the filter.
bool remove_accept_encoding_header = 8;

// Value from 9 to 15 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 12
// which will produce a 4096 bytes window. For more details about this parameter, please refer to
// zlib manual > deflateInit2.
google.protobuf.UInt32Value window_bits = 9 [(validate.rules).uint32 = {lte: 15 gte: 9}];

// Set of configuration parameters common for all compression filters. If this field is set then
// the fields `content_length`, `content_type`, `disable_on_etag_header` and
// `remove_accept_encoding_header` are ignored.
compressor.v3.Compressor compressor = 10;
}
7 changes: 5 additions & 2 deletions docs/root/configuration/http/http_filters/gzip_filter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ By *default* compression will be *skipped* when:
that the "gzip" will have a higher weight then "\*". For example, if *accept-encoding*
is "gzip;q=0,\*;q=1", the filter will not compress. But if the header is set to
"\*;q=0,gzip;q=1", the filter will compress.
- A request whose *accept-encoding* header includes "identity".
- A request whose *accept-encoding* header includes any encoding type with a higher
weight than "gzip"'s given the corresponding compression filter is present in the chain.
- A response contains a *content-encoding* header.
- A response contains a *cache-control* header whose value includes "no-transform".
- A response contains a *transfer-encoding* header whose value includes "gzip".
Expand Down Expand Up @@ -80,7 +81,9 @@ Every configured Gzip filter has statistics rooted at <stat_prefix>.gzip.* with
not_compressed, Counter, Number of requests not compressed.
no_accept_header, Counter, Number of requests with no accept header sent.
header_identity, Counter, Number of requests sent with "identity" set as the *accept-encoding*.
header_gzip, Counter, Number of requests sent with "gzip" set as the *accept-encoding*.
header_gzip, Counter, Number of requests sent with "gzip" set as the *accept-encoding*. This counter is deprecated in favour of *header_compressor_used*.
header_compressor_used, Counter, Number of requests sent with "gzip" set as the *accept-encoding*.
header_compressor_overshadowed, Counter, Number of requests skipped by this filter instance because they were handled by another filter in the same filter chain.
header_wildcard, Counter, Number of requests sent with "\*" set as the *accept-encoding*.
header_not_valid, Counter, Number of requests sent with a not valid *accept-encoding* header (aka "q=0" or an unsupported encoding type).
total_uncompressed_bytes, Counter, The total uncompressed bytes of all the requests that were marked for compression.
Expand Down
6 changes: 5 additions & 1 deletion docs/root/intro/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ Deprecated items below are listed in chronological order.
* The `header_fields`, `custom_header_fields`, and `additional_headers` fields for the route checker
tool have been deprecated in favor of `request_header_fields`, `response_header_fields`,
`additional_request_headers`, and `additional_response_headers`.

* The `content_length`, `content_type`, `disable_on_etag_header` and `remove_accept_encoding_header`
fields in :ref:`HTTP Gzip filter config <envoy_api_msg_config.filter.http.gzip.v2.Gzip>` have
been deprecated in favor of `compressor`.
* The statistics counter `header_gzip` in :ref:`HTTP Gzip filter <config_http_filters_gzip>`
has been deprecated in favor of `header_compressor_used`.

1.13.0 (January 20, 2020)
=========================
Expand Down
5 changes: 4 additions & 1 deletion generated_api_shadow/envoy/config/filter/http/gzip/v2/BUILD

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

29 changes: 24 additions & 5 deletions generated_api_shadow/envoy/config/filter/http/gzip/v2/gzip.proto

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.

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

7 changes: 1 addition & 6 deletions source/extensions/filters/http/gzip/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ envoy_cc_library(
srcs = ["gzip_filter.cc"],
hdrs = ["gzip_filter.h"],
deps = [
"//include/envoy/http:filter_interface",
"//include/envoy/json:json_object_interface",
"//include/envoy/runtime:runtime_interface",
"//source/common/buffer:buffer_lib",
"//source/common/compressor:compressor_lib",
"//source/common/http:header_map_lib",
"//source/common/http:headers_lib",
"//source/common/protobuf",
"//source/extensions/filters/http/common/compressor:compressor_lib",
"@envoy_api//envoy/extensions/filters/http/gzip/v3:pkg_cc_proto",
],
)
Expand All @@ -35,7 +31,6 @@ envoy_cc_extension(
hdrs = ["config.h"],
security_posture = "robust_to_untrusted_downstream",
deps = [
"//include/envoy/registry",
"//source/extensions/filters/http:well_known_names",
"//source/extensions/filters/http/common:factory_base_lib",
"//source/extensions/filters/http/gzip:gzip_filter_lib",
Expand Down
8 changes: 2 additions & 6 deletions source/extensions/filters/http/gzip/config.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "extensions/filters/http/gzip/config.h"

#include "envoy/extensions/filters/http/gzip/v3/gzip.pb.h"
#include "envoy/extensions/filters/http/gzip/v3/gzip.pb.validate.h"
#include "envoy/registry/registry.h"

#include "extensions/filters/http/gzip/gzip_filter.h"

namespace Envoy {
Expand All @@ -14,10 +10,10 @@ namespace Gzip {
Http::FilterFactoryCb GzipFilterFactory::createFilterFactoryFromProtoTyped(
const envoy::extensions::filters::http::gzip::v3::Gzip& proto_config,
const std::string& stats_prefix, Server::Configuration::FactoryContext& context) {
GzipFilterConfigSharedPtr config = std::make_shared<GzipFilterConfig>(
Common::Compressors::CompressorFilterConfigSharedPtr config = std::make_shared<GzipFilterConfig>(
proto_config, stats_prefix, context.scope(), context.runtime());
return [config](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamFilter(std::make_shared<GzipFilter>(config));
callbacks.addStreamFilter(std::make_shared<Common::Compressors::CompressorFilter>(config));
};
}

Expand Down
Loading

0 comments on commit c85bf32

Please sign in to comment.