tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6ffc1d8f59c477378115d313d9becc31a08eb0ad
parent 179b725f1632d1a4e007c6d807ae537c56c7f301
Author: Randell Jesup <rjesup@mozilla.com>
Date:   Wed,  1 Oct 2025 18:45: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:
Mnetwerk/protocol/http/HttpBaseChannel.cpp | 3++-
Mnetwerk/protocol/http/nsHttpChannel.cpp | 1+
Mnetwerk/protocol/http/nsHttpResponseHead.cpp | 12++++++++++++
Mnetwerk/protocol/http/nsHttpResponseHead.h | 2++
4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -1567,7 +1567,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;