commit e810283b0d941c394cfc63e8ad3efdf93da282b0
parent eb7cdb05c4bcd0835692824bbf9741f6857e668d
Author: Randell Jesup <rjesup@mozilla.com>
Date: Wed, 15 Oct 2025 21:17:46 +0000
Bug 1994472: Strip Content-Encoding when saving a cache item that's a dictionary r=necko-reviewers,valentin,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D268731
Diffstat:
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -1521,7 +1521,6 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
char* cePtr = contentEncoding.BeginWriting();
uint32_t count = 0;
- bool removeEncodings = false;
while (char* val = nsCRT::strtok(cePtr, HTTP_LWS ",", &cePtr)) {
if (++count > 16) {
// For compatibility with old code, we will just carry on without
@@ -1563,8 +1562,15 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
}
if (from.EqualsLiteral("dcb") || from.EqualsLiteral("dcz")) {
MOZ_ASSERT(XRE_IsParentProcess());
- removeEncodings = true;
}
+ // dcb and dcz encodings are removed when it's decompressed (always in
+ // the parent process). However, in theory you could have
+ // Content-Encoding: dcb,gzip
+ // in which case we could pass it down to the content process as
+ // Content-Encoding: gzip. We won't do that; we'll remove all
+ // compressors if we need to remove any. This double compression of course
+ // is silly, but supported by the spec.
+
nextListener = converter;
} else {
if (val) {
@@ -1576,21 +1582,6 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
}
}
- // dcb and dcz encodings are removed when it's decompressed (always in
- // the parent process). However, in theory you could have
- // Content-Encoding: dcb,gzip
- // in which case we could pass it down to the content process as
- // Content-Encoding: gzip. We won't do that; we'll remove all compressors
- // if we need to remove any.
- // This double compression of course is silly, but supported by the spec.
- if (removeEncodings) {
- // if we have dcb or dcz, all content-encodings in the header should
- // be removed as we're decompressing before the tee in the parent
- // process
- LOG(("Changing Content-Encoding from '%s' to ''", contentEncoding.get()));
- // Can't use SetHeader; we need to overwrite the current value
- rv = mResponseHead->SetHeaderOverride(nsHttp::Content_Encoding, ""_ns);
- }
*aNewNextListener = do_AddRef(nextListener).take();
return NS_OK;
}
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -6310,6 +6310,19 @@ nsresult nsHttpChannel::DoInstallCacheListener(bool aIsDictionaryCompressed,
if (NS_FAILED(rv)) {
return rv;
}
+ // if we have dcb or dcz or if this is Use-As-Dictionary, all
+ // content-encodings in the header should be removed as we're
+ // decompressing before the tee in the parent process
+ LOG(
+ ("Clearing Content-Encoding since we're dictionary-compressed or are "
+ "a dictionary"));
+ // Can't use SetHeader; we need to overwrite the current value
+ rv = mResponseHead->SetHeaderOverride(nsHttp::Content_Encoding, ""_ns);
+ if (NS_FAILED(rv)) {
+ mCacheEntry->AsyncDoom(nullptr);
+ return rv;
+ }
+
// Remove Available-Dictionary from Vary header if present. This
// avoids us refusing to match on a future load, for example if this
// dictionary was decoded from an earlier version using a dictionary