Line data Source code
1 : #include "source/extensions/compression/gzip/decompressor/config.h" 2 : 3 : namespace Envoy { 4 : namespace Extensions { 5 : namespace Compression { 6 : namespace Gzip { 7 : namespace Decompressor { 8 : 9 : namespace { 10 : const uint32_t DefaultWindowBits = 15; 11 : const uint32_t DefaultChunkSize = 4096; 12 : // When logical OR'ed to window bits, this tells zlib library to decompress gzip data per: 13 : // inflateInit2 in https://www.zlib.net/manual.html 14 : const uint32_t GzipHeaderValue = 16; 15 : const uint64_t DefaultMaxInflateRatio = 100; 16 : } // namespace 17 : 18 : GzipDecompressorFactory::GzipDecompressorFactory( 19 : const envoy::extensions::compression::gzip::decompressor::v3::Gzip& gzip, Stats::Scope& scope) 20 : : scope_(scope), 21 : window_bits_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(gzip, window_bits, DefaultWindowBits) | 22 : GzipHeaderValue), 23 : chunk_size_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(gzip, chunk_size, DefaultChunkSize)), 24 : max_inflate_ratio_( 25 0 : PROTOBUF_GET_WRAPPED_OR_DEFAULT(gzip, max_inflate_ratio, DefaultMaxInflateRatio)) {} 26 : 27 : Envoy::Compression::Decompressor::DecompressorPtr 28 0 : GzipDecompressorFactory::createDecompressor(const std::string& stats_prefix) { 29 0 : auto decompressor = 30 0 : std::make_unique<ZlibDecompressorImpl>(scope_, stats_prefix, chunk_size_, max_inflate_ratio_); 31 0 : decompressor->init(window_bits_); 32 0 : return decompressor; 33 0 : } 34 : 35 : Envoy::Compression::Decompressor::DecompressorFactoryPtr 36 : GzipDecompressorLibraryFactory::createDecompressorFactoryFromProtoTyped( 37 : const envoy::extensions::compression::gzip::decompressor::v3::Gzip& proto_config, 38 0 : Server::Configuration::FactoryContext& context) { 39 0 : return std::make_unique<GzipDecompressorFactory>(proto_config, context.scope()); 40 0 : } 41 : 42 : /** 43 : * Static registration for the gzip decompressor. @see NamedDecompressorLibraryConfigFactory. 44 : */ 45 : REGISTER_FACTORY(GzipDecompressorLibraryFactory, 46 : Envoy::Compression::Decompressor::NamedDecompressorLibraryConfigFactory); 47 : } // namespace Decompressor 48 : } // namespace Gzip 49 : } // namespace Compression 50 : } // namespace Extensions 51 : } // namespace Envoy