commit 805e20dc6982730d34747ec9b564590a1e8fea66
parent c15147919a0aa9107654e8ad7f1ad4807eaa1f7f
Author: Randell Jesup <rjesup@mozilla.com>
Date: Wed, 1 Oct 2025 18:45:53 +0000
Bug 1917963: Break out adding Accept-Encoding headers r=necko-reviewers,sunil,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D258119
Diffstat:
4 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -651,7 +651,7 @@ bool HttpChannelParent::DoAsyncOpen(
MOZ_ASSERT(!mBgParent);
MOZ_ASSERT(mPromise.IsEmpty());
- // Wait for HttpBackgrounChannel to continue the async open procedure.
+ // Wait for HttpBackgroundChannel to continue the async open procedure.
++mAsyncOpenBarrier;
RefPtr<HttpChannelParent> self = this;
WaitForBgParent(mChannel->ChannelId())
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -1330,7 +1330,7 @@ nsresult nsHttpChannel::Connect() {
// Step 8.18 of HTTP-network-or-cache fetch
// https://fetch.spec.whatwg.org/#http-network-or-cache-fetch
nsAutoCString rangeVal;
- if (NS_SUCCEEDED(GetRequestHeader("Range"_ns, rangeVal))) {
+ if (NS_SUCCEEDED(mRequestHead.GetHeader(nsHttp::Range, rangeVal))) {
SetRequestHeader("Accept-Encoding"_ns, "identity"_ns, true);
}
@@ -1953,6 +1953,15 @@ nsresult nsHttpChannel::SetupChannelForTransaction() {
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
}
+ } else {
+ // If we add a Range header, Accept-Encoding needs to be set to
+ // "identity" and any http additions to the headers aren't allowed to
+ // override that, so we don't try. Section 4.5 step 8.19 and 8.20 of
+ // HTTP-network-or-cache fetch
+ // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch
+ rv = mHttpHandler->AddEncodingHeaders(&mRequestHead,
+ mURI->SchemeIs("https"), mURI);
+ if (NS_FAILED(rv)) return rv;
}
// See bug #466080. Transfer LOAD_ANONYMOUS flag to socket-layer.
diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -649,6 +649,8 @@ nsresult nsHttpHandler::InitConnectionMgr() {
mBeConservativeForProxy);
}
+// We're using RequestOverride because this can get called when these are
+// set by Fetch from the old request
nsresult nsHttpHandler::AddStandardRequestHeaders(
nsHttpRequestHead* request, bool isSecure,
ExtContentPolicyType aContentPolicyType, bool aShouldResistFingerprinting) {
@@ -716,6 +718,20 @@ nsresult nsHttpHandler::AddStandardRequestHeaders(
return NS_OK;
}
+nsresult nsHttpHandler::AddEncodingHeaders(nsHttpRequestHead* request,
+ bool isSecure, nsIURI* aURI) {
+ // Add the "Accept-Encoding" header and any dictionary headers
+ nsresult rv;
+ if (isSecure) {
+ rv = request->SetHeader(nsHttp::Accept_Encoding, mHttpsAcceptEncodings,
+ false, nsHttpHeaderArray::eVarietyRequestOverride);
+ } else {
+ rv = request->SetHeader(nsHttp::Accept_Encoding, mHttpAcceptEncodings,
+ false, nsHttpHeaderArray::eVarietyRequestOverride);
+ }
+ return rv;
+}
+
nsresult nsHttpHandler::AddConnectionHeader(nsHttpRequestHead* request,
uint32_t caps) {
// RFC2616 section 19.6.2 states that the "Connection: keep-alive"
diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h
@@ -120,6 +120,8 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,
nsHttpRequestHead*, bool isSecure,
ExtContentPolicyType aContentPolicyType,
bool aShouldResistFingerprinting);
+ [[nodiscard]] nsresult AddEncodingHeaders(nsHttpRequestHead* request,
+ bool isSecure, nsIURI* aURI);
[[nodiscard]] nsresult AddConnectionHeader(nsHttpRequestHead*, uint32_t caps);
bool IsAcceptableEncoding(const char* encoding, bool isSecure);