diff --git a/CODEOWNERS b/CODEOWNERS index b82652d16143..9a7d0f06b94a 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -114,3 +114,6 @@ extensions/filters/common/original_src @snowp @klarose /*/extensions/filters/network/local_ratelimit @mattklein123 @junr03 /*/extensions/filters/http/aws_request_signing @rgs1 @derekargueta @mattklein123 @marcomagdy /*/extensions/filters/http/aws_lambda @mattklein123 @marcomagdy @lavignes +# Compression +/*/extensions/compression/common @junr03 @rojkov +/*/extensions/compression/gzip @junr03 @rojkov diff --git a/api/BUILD b/api/BUILD index 2472352ab2bd..f5bd8c1a8d0b 100644 --- a/api/BUILD +++ b/api/BUILD @@ -162,6 +162,7 @@ proto_library( "//envoy/extensions/common/ratelimit/v3:pkg", "//envoy/extensions/common/tap/v3:pkg", "//envoy/extensions/compression/gzip/compressor/v3:pkg", + "//envoy/extensions/compression/gzip/decompressor/v3:pkg", "//envoy/extensions/filters/common/fault/v3:pkg", "//envoy/extensions/filters/http/adaptive_concurrency/v3:pkg", "//envoy/extensions/filters/http/aws_lambda/v3:pkg", diff --git a/api/envoy/extensions/compression/gzip/compressor/v3/gzip.proto b/api/envoy/extensions/compression/gzip/compressor/v3/gzip.proto index 7508e17df221..d4d60eaa43ee 100644 --- a/api/envoy/extensions/compression/gzip/compressor/v3/gzip.proto +++ b/api/envoy/extensions/compression/gzip/compressor/v3/gzip.proto @@ -13,7 +13,7 @@ option java_outer_classname = "GzipProto"; option java_multiple_files = true; option (udpa.annotations.file_status).package_version_status = ACTIVE; -// [#protodoc-title: Gzip] +// [#protodoc-title: Gzip Compressor] // [#extension: envoy.compression.gzip.compressor] // [#next-free-field: 6] diff --git a/api/envoy/extensions/compression/gzip/decompressor/v3/BUILD b/api/envoy/extensions/compression/gzip/decompressor/v3/BUILD new file mode 100644 index 000000000000..ef3541ebcb1d --- /dev/null +++ b/api/envoy/extensions/compression/gzip/decompressor/v3/BUILD @@ -0,0 +1,9 @@ +# DO NOT EDIT. This file is generated by tools/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"], +) diff --git a/api/envoy/extensions/compression/gzip/decompressor/v3/gzip.proto b/api/envoy/extensions/compression/gzip/decompressor/v3/gzip.proto new file mode 100644 index 000000000000..097531ab1e9f --- /dev/null +++ b/api/envoy/extensions/compression/gzip/decompressor/v3/gzip.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; + +package envoy.extensions.compression.gzip.decompressor.v3; + +import "google/protobuf/wrappers.proto"; + +import "udpa/annotations/migrate.proto"; +import "udpa/annotations/status.proto"; +import "udpa/annotations/versioning.proto"; +import "validate/validate.proto"; + +option java_package = "io.envoyproxy.envoy.extensions.compression.gzip.decompressor.v3"; +option java_outer_classname = "GzipProto"; +option java_multiple_files = true; +option (udpa.annotations.file_status).package_version_status = ACTIVE; + +// [#protodoc-title: Gzip Decompressor] +// [#extension: envoy.compression.gzip.decompressor] + +message Gzip { + // Value from 9 to 15 that represents the base two logarithmic of the decompressor's window size. + // The decompression window size needs to be equal or larger than the compression window size. + // The default is 15 per zlib's manual. For more details about this parameter, please refer to + // zlib manual > inflateInit2. + google.protobuf.UInt32Value window_bits = 1 [(validate.rules).uint32 = {lte: 15 gte: 9}]; + + // Value for zlib's decompressor output buffer. If not set, defaults to 4096. + // See https://www.zlib.net/manual.html for more details. + google.protobuf.UInt32Value chunk_size = 2 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; +} diff --git a/api/versioning/BUILD b/api/versioning/BUILD index 4d768d09a015..e23f851b221e 100644 --- a/api/versioning/BUILD +++ b/api/versioning/BUILD @@ -45,6 +45,7 @@ proto_library( "//envoy/extensions/common/ratelimit/v3:pkg", "//envoy/extensions/common/tap/v3:pkg", "//envoy/extensions/compression/gzip/compressor/v3:pkg", + "//envoy/extensions/compression/gzip/decompressor/v3:pkg", "//envoy/extensions/filters/common/fault/v3:pkg", "//envoy/extensions/filters/http/adaptive_concurrency/v3:pkg", "//envoy/extensions/filters/http/aws_lambda/v3:pkg", diff --git a/generated_api_shadow/envoy/extensions/compression/gzip/compressor/v3/gzip.proto b/generated_api_shadow/envoy/extensions/compression/gzip/compressor/v3/gzip.proto index 7508e17df221..d4d60eaa43ee 100644 --- a/generated_api_shadow/envoy/extensions/compression/gzip/compressor/v3/gzip.proto +++ b/generated_api_shadow/envoy/extensions/compression/gzip/compressor/v3/gzip.proto @@ -13,7 +13,7 @@ option java_outer_classname = "GzipProto"; option java_multiple_files = true; option (udpa.annotations.file_status).package_version_status = ACTIVE; -// [#protodoc-title: Gzip] +// [#protodoc-title: Gzip Compressor] // [#extension: envoy.compression.gzip.compressor] // [#next-free-field: 6] diff --git a/generated_api_shadow/envoy/extensions/compression/gzip/decompressor/v3/BUILD b/generated_api_shadow/envoy/extensions/compression/gzip/decompressor/v3/BUILD new file mode 100644 index 000000000000..ef3541ebcb1d --- /dev/null +++ b/generated_api_shadow/envoy/extensions/compression/gzip/decompressor/v3/BUILD @@ -0,0 +1,9 @@ +# DO NOT EDIT. This file is generated by tools/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"], +) diff --git a/generated_api_shadow/envoy/extensions/compression/gzip/decompressor/v3/gzip.proto b/generated_api_shadow/envoy/extensions/compression/gzip/decompressor/v3/gzip.proto new file mode 100644 index 000000000000..097531ab1e9f --- /dev/null +++ b/generated_api_shadow/envoy/extensions/compression/gzip/decompressor/v3/gzip.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; + +package envoy.extensions.compression.gzip.decompressor.v3; + +import "google/protobuf/wrappers.proto"; + +import "udpa/annotations/migrate.proto"; +import "udpa/annotations/status.proto"; +import "udpa/annotations/versioning.proto"; +import "validate/validate.proto"; + +option java_package = "io.envoyproxy.envoy.extensions.compression.gzip.decompressor.v3"; +option java_outer_classname = "GzipProto"; +option java_multiple_files = true; +option (udpa.annotations.file_status).package_version_status = ACTIVE; + +// [#protodoc-title: Gzip Decompressor] +// [#extension: envoy.compression.gzip.decompressor] + +message Gzip { + // Value from 9 to 15 that represents the base two logarithmic of the decompressor's window size. + // The decompression window size needs to be equal or larger than the compression window size. + // The default is 15 per zlib's manual. For more details about this parameter, please refer to + // zlib manual > inflateInit2. + google.protobuf.UInt32Value window_bits = 1 [(validate.rules).uint32 = {lte: 15 gte: 9}]; + + // Value for zlib's decompressor output buffer. If not set, defaults to 4096. + // See https://www.zlib.net/manual.html for more details. + google.protobuf.UInt32Value chunk_size = 2 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; +} diff --git a/include/envoy/compression/compressor/config.h b/include/envoy/compression/compressor/config.h index af8f0b9997fa..3ef89c9f0d55 100644 --- a/include/envoy/compression/compressor/config.h +++ b/include/envoy/compression/compressor/config.h @@ -15,6 +15,8 @@ class NamedCompressorLibraryConfigFactory : public Config::TypedFactory { virtual CompressorFactoryPtr createCompressorFactoryFromProto(const Protobuf::Message& config, Server::Configuration::FactoryContext& context) PURE; + + std::string category() const override { return "envoy.compression.compressor"; } }; } // namespace Compressor diff --git a/include/envoy/compression/decompressor/BUILD b/include/envoy/compression/decompressor/BUILD new file mode 100644 index 000000000000..60a8e9cb7eeb --- /dev/null +++ b/include/envoy/compression/decompressor/BUILD @@ -0,0 +1,35 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_library", + "envoy_package", +) + +envoy_package() + +envoy_cc_library( + name = "decompressor_config_interface", + hdrs = ["config.h"], + deps = [ + ":decompressor_factory_interface", + "//include/envoy/config:typed_config_interface", + "//include/envoy/server:filter_config_interface", + ], +) + +envoy_cc_library( + name = "decompressor_factory_interface", + hdrs = ["factory.h"], + deps = [ + ":decompressor_interface", + ], +) + +envoy_cc_library( + name = "decompressor_interface", + hdrs = ["decompressor.h"], + deps = [ + "//include/envoy/buffer:buffer_interface", + ], +) diff --git a/include/envoy/compression/decompressor/config.h b/include/envoy/compression/decompressor/config.h new file mode 100644 index 000000000000..15ecd1255d6a --- /dev/null +++ b/include/envoy/compression/decompressor/config.h @@ -0,0 +1,24 @@ +#pragma once + +#include "envoy/compression/decompressor/factory.h" +#include "envoy/config/typed_config.h" +#include "envoy/server/filter_config.h" + +namespace Envoy { +namespace Compression { +namespace Decompressor { + +class NamedDecompressorLibraryConfigFactory : public Config::TypedFactory { +public: + ~NamedDecompressorLibraryConfigFactory() override = default; + + virtual DecompressorFactoryPtr + createDecompressorFactoryFromProto(const Protobuf::Message& config, + Server::Configuration::FactoryContext& context) PURE; + + std::string category() const override { return "envoy.compression.decompressor"; } +}; + +} // namespace Decompressor +} // namespace Compression +} // namespace Envoy \ No newline at end of file diff --git a/include/envoy/decompressor/decompressor.h b/include/envoy/compression/decompressor/decompressor.h similarity index 84% rename from include/envoy/decompressor/decompressor.h rename to include/envoy/compression/decompressor/decompressor.h index d694aa50ca1c..c0518a5789b3 100644 --- a/include/envoy/decompressor/decompressor.h +++ b/include/envoy/compression/decompressor/decompressor.h @@ -3,6 +3,7 @@ #include "envoy/buffer/buffer.h" namespace Envoy { +namespace Compression { namespace Decompressor { /** @@ -21,5 +22,8 @@ class Decompressor { Buffer::Instance& output_buffer) PURE; }; +using DecompressorPtr = std::unique_ptr; + } // namespace Decompressor +} // namespace Compression } // namespace Envoy diff --git a/include/envoy/compression/decompressor/factory.h b/include/envoy/compression/decompressor/factory.h new file mode 100644 index 000000000000..e0a38713b42f --- /dev/null +++ b/include/envoy/compression/decompressor/factory.h @@ -0,0 +1,25 @@ +#pragma once + +#include "envoy/compression/decompressor/decompressor.h" + +namespace Envoy { +namespace Compression { +namespace Decompressor { + +class DecompressorFactory { +public: + virtual ~DecompressorFactory() = default; + + virtual DecompressorPtr createDecompressor() PURE; + virtual const std::string& statsPrefix() const PURE; + // TODO(junr03): this method assumes that decompressors are used on http messages. + // A more generic method might be `hint()` which gives the user of the decompressor a hint about + // the type of decompression that it can perform. + virtual const std::string& contentEncoding() const PURE; +}; + +using DecompressorFactoryPtr = std::unique_ptr; + +} // namespace Decompressor +} // namespace Compression +} // namespace Envoy \ No newline at end of file diff --git a/source/common/common/zlib/base.h b/source/common/common/zlib/base.h index 4f427fb90985..f8b89cb25335 100644 --- a/source/common/common/zlib/base.h +++ b/source/common/common/zlib/base.h @@ -12,6 +12,7 @@ namespace Zlib { /** * Shared code between the compressor and the decompressor. */ +// TODO(junr03): move to extensions tree once the compressor side is moved to extensions. class Base { public: Base(uint64_t chunk_size, std::function zstream_deleter); diff --git a/source/common/decompressor/BUILD b/source/common/decompressor/BUILD deleted file mode 100644 index dfdf8f9b90ed..000000000000 --- a/source/common/decompressor/BUILD +++ /dev/null @@ -1,23 +0,0 @@ -licenses(["notice"]) # Apache 2 - -load( - "//bazel:envoy_build_system.bzl", - "envoy_cc_library", - "envoy_package", -) - -envoy_package() - -envoy_cc_library( - name = "decompressor_lib", - srcs = ["zlib_decompressor_impl.cc"], - hdrs = ["zlib_decompressor_impl.h"], - external_deps = ["zlib"], - deps = [ - "//include/envoy/decompressor:decompressor_interface", - "//source/common/buffer:buffer_lib", - "//source/common/common:assert_lib", - "//source/common/common:minimal_logger_lib", - "//source/common/common:zlib_base_lib", - ], -) diff --git a/source/extensions/compression/common/compressor/factory_base.h b/source/extensions/compression/common/compressor/factory_base.h index fe2ddefb9c32..472d754cb9cd 100644 --- a/source/extensions/compression/common/compressor/factory_base.h +++ b/source/extensions/compression/common/compressor/factory_base.h @@ -26,8 +26,6 @@ class CompressorLibraryFactoryBase return std::make_unique(); } - std::string category() const override { return "envoy.compression.compressor"; } - std::string name() const override { return name_; } protected: @@ -36,6 +34,7 @@ class CompressorLibraryFactoryBase private: virtual Envoy::Compression::Compressor::CompressorFactoryPtr createCompressorFactoryFromProtoTyped(const ConfigProto&) PURE; + const std::string name_; }; diff --git a/include/envoy/decompressor/BUILD b/source/extensions/compression/common/decompressor/BUILD similarity index 53% rename from include/envoy/decompressor/BUILD rename to source/extensions/compression/common/decompressor/BUILD index 4dbcfec52980..3b3e96b3e980 100644 --- a/include/envoy/decompressor/BUILD +++ b/source/extensions/compression/common/decompressor/BUILD @@ -9,9 +9,9 @@ load( envoy_package() envoy_cc_library( - name = "decompressor_interface", - hdrs = ["decompressor.h"], + name = "decompressor_factory_base_lib", + hdrs = ["factory_base.h"], deps = [ - "//include/envoy/buffer:buffer_interface", + "//include/envoy/compression/decompressor:decompressor_config_interface", ], ) diff --git a/source/extensions/compression/common/decompressor/factory_base.h b/source/extensions/compression/common/decompressor/factory_base.h new file mode 100644 index 000000000000..98144e02e1b6 --- /dev/null +++ b/source/extensions/compression/common/decompressor/factory_base.h @@ -0,0 +1,43 @@ +#pragma once + +#include "envoy/compression/decompressor/config.h" + +namespace Envoy { +namespace Extensions { +namespace Compression { +namespace Common { +namespace Decompressor { + +template +class DecompressorLibraryFactoryBase + : public Envoy::Compression::Decompressor::NamedDecompressorLibraryConfigFactory { +public: + Envoy::Compression::Decompressor::DecompressorFactoryPtr + createDecompressorFactoryFromProto(const Protobuf::Message& proto_config, + Server::Configuration::FactoryContext& context) override { + return createDecompressorFactoryFromProtoTyped( + MessageUtil::downcastAndValidate(proto_config, + context.messageValidationVisitor())); + } + + ProtobufTypes::MessagePtr createEmptyConfigProto() override { + return std::make_unique(); + } + + std::string name() const override { return name_; } + +protected: + DecompressorLibraryFactoryBase(const std::string& name) : name_(name) {} + +private: + virtual Envoy::Compression::Decompressor::DecompressorFactoryPtr + createDecompressorFactoryFromProtoTyped(const ConfigProto&) PURE; + + const std::string name_; +}; + +} // namespace Decompressor +} // namespace Common +} // namespace Compression +} // namespace Extensions +} // namespace Envoy diff --git a/source/extensions/compression/gzip/decompressor/BUILD b/source/extensions/compression/gzip/decompressor/BUILD new file mode 100644 index 000000000000..bfb693b8ac64 --- /dev/null +++ b/source/extensions/compression/gzip/decompressor/BUILD @@ -0,0 +1,37 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_extension", + "envoy_cc_library", + "envoy_package", +) + +envoy_package() + +envoy_cc_library( + name = "zlib_decompressor_impl_lib", + srcs = ["zlib_decompressor_impl.cc"], + hdrs = ["zlib_decompressor_impl.h"], + external_deps = ["zlib"], + deps = [ + "//include/envoy/compression/decompressor:decompressor_interface", + "//source/common/buffer:buffer_lib", + "//source/common/common:assert_lib", + "//source/common/common:minimal_logger_lib", + "//source/common/common:zlib_base_lib", + ], +) + +envoy_cc_extension( + name = "config", + srcs = ["config.cc"], + hdrs = ["config.h"], + security_posture = "robust_to_untrusted_downstream", + deps = [ + ":zlib_decompressor_impl_lib", + "//source/common/http:headers_lib", + "//source/extensions/compression/common/decompressor:decompressor_factory_base_lib", + "@envoy_api//envoy/extensions/compression/gzip/decompressor/v3:pkg_cc_proto", + ], +) diff --git a/source/extensions/compression/gzip/decompressor/config.cc b/source/extensions/compression/gzip/decompressor/config.cc new file mode 100644 index 000000000000..8dc898be7060 --- /dev/null +++ b/source/extensions/compression/gzip/decompressor/config.cc @@ -0,0 +1,40 @@ +#include "extensions/compression/gzip/decompressor/config.h" + +namespace Envoy { +namespace Extensions { +namespace Compression { +namespace Gzip { +namespace Decompressor { + +namespace { +const uint32_t DefaultWindowBits = 12; +const uint32_t DefaultChunkSize = 4096; +} // namespace + +GzipDecompressorFactory::GzipDecompressorFactory( + const envoy::extensions::compression::gzip::decompressor::v3::Gzip& gzip) + : window_bits_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(gzip, window_bits, DefaultWindowBits)), + chunk_size_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(gzip, chunk_size, DefaultChunkSize)) {} + +Envoy::Compression::Decompressor::DecompressorPtr GzipDecompressorFactory::createDecompressor() { + auto decompressor = std::make_unique(chunk_size_); + decompressor->init(window_bits_); + return decompressor; +} + +Envoy::Compression::Decompressor::DecompressorFactoryPtr +GzipDecompressorLibraryFactory::createDecompressorFactoryFromProtoTyped( + const envoy::extensions::compression::gzip::decompressor::v3::Gzip& proto_config) { + return std::make_unique(proto_config); +} + +/** + * Static registration for the gzip decompressor. @see NamedDecompressorLibraryConfigFactory. + */ +REGISTER_FACTORY(GzipDecompressorLibraryFactory, + Envoy::Compression::Decompressor::NamedDecompressorLibraryConfigFactory); +} // namespace Decompressor +} // namespace Gzip +} // namespace Compression +} // namespace Extensions +} // namespace Envoy diff --git a/source/extensions/compression/gzip/decompressor/config.h b/source/extensions/compression/gzip/decompressor/config.h new file mode 100644 index 000000000000..9a99398b23a4 --- /dev/null +++ b/source/extensions/compression/gzip/decompressor/config.h @@ -0,0 +1,59 @@ +#pragma once + +#include "envoy/compression/decompressor/config.h" +#include "envoy/extensions/compression/gzip/decompressor/v3/gzip.pb.h" +#include "envoy/extensions/compression/gzip/decompressor/v3/gzip.pb.validate.h" + +#include "common/http/headers.h" + +#include "extensions/compression/common/decompressor/factory_base.h" +#include "extensions/compression/gzip/decompressor/zlib_decompressor_impl.h" + +namespace Envoy { +namespace Extensions { +namespace Compression { +namespace Gzip { +namespace Decompressor { + +namespace { +const std::string& gzipStatsPrefix() { CONSTRUCT_ON_FIRST_USE(std::string, "gzip."); } +const std::string& gzipExtensionName() { + CONSTRUCT_ON_FIRST_USE(std::string, "envoy.compression.gzip.decompressor"); +} + +} // namespace + +class GzipDecompressorFactory : public Envoy::Compression::Decompressor::DecompressorFactory { +public: + GzipDecompressorFactory(const envoy::extensions::compression::gzip::decompressor::v3::Gzip& gzip); + + // Envoy::Compression::Decompressor::DecompressorFactory + Envoy::Compression::Decompressor::DecompressorPtr createDecompressor() override; + const std::string& statsPrefix() const override { return gzipStatsPrefix(); } + const std::string& contentEncoding() const override { + return Http::Headers::get().ContentEncodingValues.Gzip; + } + +private: + const int32_t window_bits_; + const uint32_t chunk_size_; +}; + +class GzipDecompressorLibraryFactory + : public Common::Decompressor::DecompressorLibraryFactoryBase< + envoy::extensions::compression::gzip::decompressor::v3::Gzip> { +public: + GzipDecompressorLibraryFactory() : DecompressorLibraryFactoryBase(gzipExtensionName()) {} + +private: + Envoy::Compression::Decompressor::DecompressorFactoryPtr createDecompressorFactoryFromProtoTyped( + const envoy::extensions::compression::gzip::decompressor::v3::Gzip& config) override; +}; + +DECLARE_FACTORY(GzipDecompressorLibraryFactory); + +} // namespace Decompressor +} // namespace Gzip +} // namespace Compression +} // namespace Extensions +} // namespace Envoy diff --git a/source/common/decompressor/zlib_decompressor_impl.cc b/source/extensions/compression/gzip/decompressor/zlib_decompressor_impl.cc similarity index 91% rename from source/common/decompressor/zlib_decompressor_impl.cc rename to source/extensions/compression/gzip/decompressor/zlib_decompressor_impl.cc index 55dffc6d3609..4a1ca6251098 100644 --- a/source/common/decompressor/zlib_decompressor_impl.cc +++ b/source/extensions/compression/gzip/decompressor/zlib_decompressor_impl.cc @@ -1,4 +1,4 @@ -#include "common/decompressor/zlib_decompressor_impl.h" +#include "extensions/compression/gzip/decompressor/zlib_decompressor_impl.h" #include @@ -9,6 +9,9 @@ #include "absl/container/fixed_array.h" namespace Envoy { +namespace Extensions { +namespace Compression { +namespace Gzip { namespace Decompressor { ZlibDecompressorImpl::ZlibDecompressorImpl() : ZlibDecompressorImpl(4096) {} @@ -75,4 +78,7 @@ bool ZlibDecompressorImpl::inflateNext() { } } // namespace Decompressor +} // namespace Gzip +} // namespace Compression +} // namespace Extensions } // namespace Envoy diff --git a/source/common/decompressor/zlib_decompressor_impl.h b/source/extensions/compression/gzip/decompressor/zlib_decompressor_impl.h similarity index 84% rename from source/common/decompressor/zlib_decompressor_impl.h rename to source/extensions/compression/gzip/decompressor/zlib_decompressor_impl.h index 8d5627fc6c31..77c49e83d56d 100644 --- a/source/common/decompressor/zlib_decompressor_impl.h +++ b/source/extensions/compression/gzip/decompressor/zlib_decompressor_impl.h @@ -1,6 +1,6 @@ #pragma once -#include "envoy/decompressor/decompressor.h" +#include "envoy/compression/decompressor/decompressor.h" #include "common/common/logger.h" #include "common/common/zlib/base.h" @@ -8,13 +8,16 @@ #include "zlib.h" namespace Envoy { +namespace Extensions { +namespace Compression { +namespace Gzip { namespace Decompressor { /** * Implementation of decompressor's interface. */ class ZlibDecompressorImpl : public Zlib::Base, - public Decompressor, + public Envoy::Compression::Decompressor::Decompressor, public Logger::Loggable { public: ZlibDecompressorImpl(); @@ -37,7 +40,7 @@ class ZlibDecompressorImpl : public Zlib::Base, */ void init(int64_t window_bits); - // Decompressor + // Compression::Decompressor::Decompressor void decompress(const Buffer::Instance& input_buffer, Buffer::Instance& output_buffer) override; // Flag to track whether error occurred during decompression. @@ -49,4 +52,7 @@ class ZlibDecompressorImpl : public Zlib::Base, }; } // namespace Decompressor +} // namespace Gzip +} // namespace Compression +} // namespace Extensions } // namespace Envoy diff --git a/source/extensions/extensions_build_config.bzl b/source/extensions/extensions_build_config.bzl index d064296d8370..434a74d949ce 100644 --- a/source/extensions/extensions_build_config.bzl +++ b/source/extensions/extensions_build_config.bzl @@ -21,6 +21,7 @@ EXTENSIONS = { # "envoy.compression.gzip.compressor": "//source/extensions/compression/gzip/compressor:config", + "envoy.compression.gzip.decompressor": "//source/extensions/compression/gzip/decompressor:config", # # gRPC Credentials Plugins diff --git a/test/common/stats/BUILD b/test/common/stats/BUILD index 72e04a9c0815..909e4a4c25f4 100644 --- a/test/common/stats/BUILD +++ b/test/common/stats/BUILD @@ -157,7 +157,6 @@ envoy_cc_fuzz_test( ":stat_test_utility_lib", "//source/common/buffer:buffer_lib", "//source/common/common:assert_lib", - "//source/common/decompressor:decompressor_lib", "//source/common/stats:symbol_table_lib", "//test/fuzz:utility_lib", ], diff --git a/test/extensions/compression/gzip/BUILD b/test/extensions/compression/gzip/BUILD index 98c9de21486e..772bc17016ad 100644 --- a/test/extensions/compression/gzip/BUILD +++ b/test/extensions/compression/gzip/BUILD @@ -15,7 +15,7 @@ envoy_cc_fuzz_test( deps = [ "//source/common/buffer:buffer_lib", "//source/common/common:assert_lib", - "//source/common/decompressor:decompressor_lib", "//source/extensions/compression/gzip/compressor:compressor_lib", + "//source/extensions/compression/gzip/decompressor:zlib_decompressor_impl_lib", ], ) diff --git a/test/extensions/compression/gzip/compressor_fuzz_test.cc b/test/extensions/compression/gzip/compressor_fuzz_test.cc index b9a194c0c15c..da76007c8989 100644 --- a/test/extensions/compression/gzip/compressor_fuzz_test.cc +++ b/test/extensions/compression/gzip/compressor_fuzz_test.cc @@ -1,8 +1,8 @@ #include "common/buffer/buffer_impl.h" #include "common/common/assert.h" -#include "common/decompressor/zlib_decompressor_impl.h" #include "extensions/compression/gzip/compressor/zlib_compressor_impl.h" +#include "extensions/compression/gzip/decompressor/zlib_decompressor_impl.h" #include "test/fuzz/fuzz_runner.h" diff --git a/test/common/decompressor/BUILD b/test/extensions/compression/gzip/decompressor/BUILD similarity index 76% rename from test/common/decompressor/BUILD rename to test/extensions/compression/gzip/decompressor/BUILD index 55703c5b25ab..e40b2953db28 100644 --- a/test/common/decompressor/BUILD +++ b/test/extensions/compression/gzip/decompressor/BUILD @@ -9,13 +9,13 @@ load( envoy_package() envoy_cc_test( - name = "decompressor_test", + name = "zlib_decompressor_impl_test", srcs = ["zlib_decompressor_impl_test.cc"], deps = [ "//source/common/common:assert_lib", "//source/common/common:hex_lib", - "//source/common/decompressor:decompressor_lib", "//source/extensions/compression/gzip/compressor:compressor_lib", + "//source/extensions/compression/gzip/decompressor:zlib_decompressor_impl_lib", "//test/test_common:utility_lib", ], ) diff --git a/test/common/decompressor/zlib_decompressor_impl_test.cc b/test/extensions/compression/gzip/decompressor/zlib_decompressor_impl_test.cc similarity index 92% rename from test/common/decompressor/zlib_decompressor_impl_test.cc rename to test/extensions/compression/gzip/decompressor/zlib_decompressor_impl_test.cc index 99e0b43e83f6..87cd0ecf5b1a 100644 --- a/test/common/decompressor/zlib_decompressor_impl_test.cc +++ b/test/extensions/compression/gzip/decompressor/zlib_decompressor_impl_test.cc @@ -1,14 +1,17 @@ #include "common/buffer/buffer_impl.h" #include "common/common/hex.h" -#include "common/decompressor/zlib_decompressor_impl.h" #include "extensions/compression/gzip/compressor/zlib_compressor_impl.h" +#include "extensions/compression/gzip/decompressor/zlib_decompressor_impl.h" #include "test/test_common/utility.h" #include "gtest/gtest.h" namespace Envoy { +namespace Extensions { +namespace Compression { +namespace Gzip { namespace Decompressor { namespace { @@ -31,13 +34,13 @@ class ZlibDecompressorImplTest : public testing::Test { for (uint64_t i = 0; i < 30; ++i) { TestUtility::feedBufferWithRandomCharacters(buffer, default_input_size * i, i); original_text.append(buffer.toString()); - compressor.compress(buffer, Compression::Compressor::State::Flush); + compressor.compress(buffer, Envoy::Compression::Compressor::State::Flush); accumulation_buffer.add(buffer); drainBuffer(buffer); } ASSERT_EQ(0, buffer.length()); - compressor.compress(buffer, Compression::Compressor::State::Finish); + compressor.compress(buffer, Envoy::Compression::Compressor::State::Finish); accumulation_buffer.add(buffer); drainBuffer(buffer); @@ -99,7 +102,7 @@ TEST_F(ZlibDecompressorImplTest, CallingChecksum) { ASSERT_EQ(0, compressor.checksum()); TestUtility::feedBufferWithRandomCharacters(compressor_buffer, 4096); - compressor.compress(compressor_buffer, Compression::Compressor::State::Flush); + compressor.compress(compressor_buffer, Envoy::Compression::Compressor::State::Flush); ASSERT_TRUE(compressor.checksum() > 0); ZlibDecompressorImpl decompressor; @@ -132,14 +135,14 @@ TEST_F(ZlibDecompressorImplTest, CompressAndDecompress) { for (uint64_t i = 0; i < 20; ++i) { TestUtility::feedBufferWithRandomCharacters(buffer, default_input_size * i, i); original_text.append(buffer.toString()); - compressor.compress(buffer, Compression::Compressor::State::Flush); + compressor.compress(buffer, Envoy::Compression::Compressor::State::Flush); accumulation_buffer.add(buffer); drainBuffer(buffer); } ASSERT_EQ(0, buffer.length()); - compressor.compress(buffer, Compression::Compressor::State::Finish); + compressor.compress(buffer, Envoy::Compression::Compressor::State::Finish); ASSERT_GE(10, buffer.length()); accumulation_buffer.add(buffer); @@ -200,14 +203,14 @@ TEST_F(ZlibDecompressorImplTest, DecompressWithSmallOutputBuffer) { for (uint64_t i = 0; i < 20; ++i) { TestUtility::feedBufferWithRandomCharacters(buffer, default_input_size * i, i); original_text.append(buffer.toString()); - compressor.compress(buffer, Compression::Compressor::State::Flush); + compressor.compress(buffer, Envoy::Compression::Compressor::State::Flush); accumulation_buffer.add(buffer); drainBuffer(buffer); } ASSERT_EQ(0, buffer.length()); - compressor.compress(buffer, Compression::Compressor::State::Finish); + compressor.compress(buffer, Envoy::Compression::Compressor::State::Finish); ASSERT_GE(10, buffer.length()); accumulation_buffer.add(buffer); @@ -278,7 +281,7 @@ TEST_F(ZlibDecompressorImplTest, CompressDecompressOfMultipleSlices) { Extensions::Compression::Gzip::Compressor::ZlibCompressorImpl::CompressionStrategy::Standard, gzip_window_bits, memory_level); - compressor.compress(buffer, Compression::Compressor::State::Flush); + compressor.compress(buffer, Envoy::Compression::Compressor::State::Flush); accumulation_buffer.add(buffer); ZlibDecompressorImpl decompressor; @@ -297,4 +300,7 @@ TEST_F(ZlibDecompressorImplTest, CompressDecompressOfMultipleSlices) { } // namespace } // namespace Decompressor +} // namespace Gzip +} // namespace Compression +} // namespace Extensions } // namespace Envoy diff --git a/test/extensions/filters/http/compressor/BUILD b/test/extensions/filters/http/compressor/BUILD index 87a1a23d04f2..1a608f282f0a 100644 --- a/test/extensions/filters/http/compressor/BUILD +++ b/test/extensions/filters/http/compressor/BUILD @@ -32,8 +32,8 @@ envoy_extension_cc_test( ], extension_name = "envoy.filters.http.compressor", deps = [ - "//source/common/decompressor:decompressor_lib", "//source/extensions/compression/gzip/compressor:config", + "//source/extensions/compression/gzip/decompressor:config", "//source/extensions/filters/http/compressor:config", "//test/integration:http_integration_lib", "//test/test_common:simulated_time_system_lib", diff --git a/test/extensions/filters/http/compressor/compressor_filter_integration_test.cc b/test/extensions/filters/http/compressor/compressor_filter_integration_test.cc index c43869f9bc8e..82e7c1cd31f7 100644 --- a/test/extensions/filters/http/compressor/compressor_filter_integration_test.cc +++ b/test/extensions/filters/http/compressor/compressor_filter_integration_test.cc @@ -1,6 +1,6 @@ #include "envoy/event/timer.h" -#include "common/decompressor/zlib_decompressor_impl.h" +#include "extensions/compression/gzip/decompressor/zlib_decompressor_impl.h" #include "test/integration/http_integration.h" #include "test/test_common/simulated_time_system.h" @@ -96,7 +96,7 @@ class CompressorIntegrationTest : public testing::TestWithParam config_; std::unique_ptr filter_; Buffer::OwnedImpl data_; - Decompressor::ZlibDecompressorImpl decompressor_; + Compression::Gzip::Decompressor::ZlibDecompressorImpl decompressor_; Buffer::OwnedImpl decompressed_data_; std::string expected_str_; Stats::TestUtil::TestStore stats_; diff --git a/tools/spelling/spelling_dictionary.txt b/tools/spelling/spelling_dictionary.txt index eac6b9880ae6..497e035e2c02 100644 --- a/tools/spelling/spelling_dictionary.txt +++ b/tools/spelling/spelling_dictionary.txt @@ -504,6 +504,7 @@ dechunked decl decls decompressor +decompressors decrement decrypt dedup