Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 5 additions & 10 deletions source/extensions/filters/http/common/compressor/compressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,8 @@ Http::FilterHeadersStatus CompressorFilter::decodeHeaders(Http::RequestHeaderMap
accept_encoding_ = std::make_unique<std::string>(accept_encoding->value().getStringView());
}

if (config_->enabled()) {
skip_compression_ = false;
if (config_->removeAcceptEncodingHeader()) {
headers.removeAcceptEncoding();
}
} else {
config_->stats().not_compressed_.inc();
if (config_->enabled() && config_->removeAcceptEncodingHeader()) {
headers.removeAcceptEncoding();
}

return Http::FilterHeadersStatus::Continue;
Expand Down Expand Up @@ -105,19 +100,19 @@ void CompressorFilter::setDecoderFilterCallbacks(Http::StreamDecoderFilterCallba

Http::FilterHeadersStatus CompressorFilter::encodeHeaders(Http::ResponseHeaderMap& headers,
bool end_stream) {
if (!end_stream && !skip_compression_ && isMinimumContentLength(headers) &&
if (!end_stream && config_->enabled() && isMinimumContentLength(headers) &&
isAcceptEncodingAllowed(headers) && isContentTypeAllowed(headers) &&
!hasCacheControlNoTransform(headers) && isEtagAllowed(headers) &&
isTransferEncodingAllowed(headers) && !headers.ContentEncoding()) {
skip_compression_ = false;
sanitizeEtagHeader(headers);
insertVaryHeader(headers);
headers.removeContentLength();
headers.setContentEncoding(config_->contentEncoding());
config_->stats().compressed_.inc();
// Finally instantiate the compressor.
compressor_ = config_->makeCompressor();
} else if (!skip_compression_) {
skip_compression_ = true;
} else {
config_->stats().not_compressed_.inc();
}
return Http::FilterHeadersStatus::Continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ TEST_F(CompressorFilterTest, DecodeHeadersWithRuntimeDisabled) {
}
}
)EOF");
EXPECT_CALL(runtime_.snapshot_, getBoolean("foo_key", true)).WillOnce(Return(false));
EXPECT_CALL(runtime_.snapshot_, getBoolean("foo_key", true))
.Times(2)
.WillRepeatedly(Return(false));
doRequest({{":method", "get"}, {"accept-encoding", "deflate, test"}}, false);
doResponseNoCompression({{":method", "get"}, {"content-length", "256"}});
}
Expand Down
4 changes: 3 additions & 1 deletion test/extensions/filters/http/gzip/gzip_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ TEST_F(GzipFilterTest, RuntimeDisabled) {
}
}
)EOF");
EXPECT_CALL(runtime_.snapshot_, getBoolean("foo_key", true)).WillOnce(Return(false));
EXPECT_CALL(runtime_.snapshot_, getBoolean("foo_key", true))
.Times(2)
.WillRepeatedly(Return(false));
doRequest({{":method", "get"}, {"accept-encoding", "deflate, gzip"}}, false);
doResponseNoCompression({{":method", "get"}, {"content-length", "256"}});
}
Expand Down