Skip to content

Commit

Permalink
[cache-filter] don't set empty content-length (envoyproxy#31454)
Browse files Browse the repository at this point in the history
Signed-off-by: Raven Black <[email protected]>
  • Loading branch information
ravenblackx authored Dec 21, 2023
1 parent 487ad2c commit 82da331
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions source/extensions/filters/http/cache/cache_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,12 @@ void CacheFilter::processSuccessfulValidation(Http::ResponseHeaderMap& response_

filter_state_ = FilterState::EncodeServingFromCache;

// Update the 304 response status code and content-length
// Replace the 304 response status code with the cached status code.
response_headers.setStatus(lookup_result_->headers_->getStatusValue());
response_headers.setContentLength(lookup_result_->headers_->getContentLengthValue());

// Remove content length header if the 304 had one; if the cache entry had a
// content length header it will be added by the header adding block below.
response_headers.removeContentLength();

// A response that has been validated should not contain an Age header as it is equivalent to a
// freshly served response from the origin, unless the 304 response has an Age header, which
Expand All @@ -553,7 +556,7 @@ void CacheFilter::processSuccessfulValidation(Http::ResponseHeaderMap& response_
// Add any missing headers from the cached response to the 304 response.
lookup_result_->headers_->iterate([&response_headers](const Http::HeaderEntry& cached_header) {
// TODO(yosrym93): Try to avoid copying the header key twice.
Http::LowerCaseString key(std::string(cached_header.key().getStringView()));
Http::LowerCaseString key(cached_header.key().getStringView());
absl::string_view value = cached_header.value().getStringView();
if (response_headers.get(key).empty()) {
response_headers.setCopy(key, value);
Expand Down

0 comments on commit 82da331

Please sign in to comment.