commit 2121596c39e539dbf6e882879103e680ad7a7369
parent d6a115c0a50f9ff8509047bfd3f2cd6b4905e609
Author: Randell Jesup <rjesup@mozilla.com>
Date: Tue, 7 Oct 2025 17:55:57 +0000
Bug 1950972: Allow changing Content-Encoding header when we decompress for cache storage r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D258160
Diffstat:
4 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -1568,7 +1568,8 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
LOG(("Changing Content-Encoding from %s to %s", contentEncoding.get(),
newEncoding.get()));
- rv = mResponseHead->SetHeader(nsHttp::Content_Encoding, newEncoding);
+ // Can't use SetHeader; we need to overwrite the current value
+ rv = mResponseHead->SetHeaderOverride(nsHttp::Content_Encoding, newEncoding);
*aNewNextListener = do_AddRef(nextListener).take();
return NS_OK;
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -6153,6 +6153,7 @@ nsresult nsHttpChannel::InstallCacheListener(int64_t offset) {
("Content-Encoding for %p: %s", this, contentEncoding.get()));
if (!dictionary.IsEmpty() || contentEncoding.Equals("dcb") ||
contentEncoding.Equals("dcz")) {
+ LOG_DICTIONARIES(("Removing Content-Encoding for %p", this));
nsCOMPtr<nsIStreamListener> listener;
// otherwise we won't convert in the parent process
SetApplyConversion(true);
diff --git a/netwerk/protocol/http/nsHttpResponseHead.cpp b/netwerk/protocol/http/nsHttpResponseHead.cpp
@@ -193,6 +193,18 @@ nsresult nsHttpResponseHead::SetHeader(const nsHttpAtom& hdr,
return SetHeader_locked(hdr, ""_ns, val, merge);
}
+// override the current value
+nsresult nsHttpResponseHead::SetHeaderOverride(const nsHttpAtom& atom,
+ const nsACString& val) {
+ RecursiveMutexAutoLock monitor(mRecursiveMutex);
+
+ if (mInVisitHeaders) {
+ return NS_ERROR_FAILURE;
+ }
+
+ return mHeaders.SetHeaderFromNet(atom, ""_ns, val, true);
+}
+
nsresult nsHttpResponseHead::SetHeader_locked(const nsHttpAtom& atom,
const nsACString& hdr,
const nsACString& val,
diff --git a/netwerk/protocol/http/nsHttpResponseHead.h b/netwerk/protocol/http/nsHttpResponseHead.h
@@ -72,6 +72,8 @@ class nsHttpResponseHead {
[[nodiscard]] nsresult SetHeader(const nsACString& h, const nsACString& v,
bool m = false);
+ [[nodiscard]] nsresult SetHeaderOverride(const nsHttpAtom& h,
+ const nsACString& v);
[[nodiscard]] nsresult SetHeader(const nsHttpAtom& h, const nsACString& v,
bool m = false);
[[nodiscard]] nsresult GetHeader(const nsHttpAtom& h, nsACString& v) const;