зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1877405 - Adding a eVarietyRequestEnforceDefault to nsHttpHeaderArray::HeaderVariety r=necko-reviewers,devtools-reviewers,bomsy,kershaw
Adding a new HeaderVariety called eVarietyRequestEnforceDefault. It allows setting request header value as default even even if the header exists. We need this to setting default header value without changing the order of the header. Differential Revision: https://phabricator.services.mozilla.com/D199991
This commit is contained in:
Родитель
69ffaa7b95
Коммит
949f77d58f
|
@ -18,12 +18,12 @@ add_task(async function () {
|
|||
await testClipboardContent(`await fetch("https://example.com/browser/devtools/client/netmonitor/test/sjs_simple-test-server.sjs", {
|
||||
"credentials": "omit",
|
||||
"headers": {
|
||||
"User-Agent": "${navigator.userAgent}",
|
||||
"Accept": "*/*",
|
||||
"Accept-Language": "en-US",
|
||||
"X-Custom-Header-1": "Custom value",
|
||||
"X-Custom-Header-2": "8.8.8.8",
|
||||
"X-Custom-Header-3": "Mon, 3 Mar 2014 11:11:11 GMT",
|
||||
"User-Agent": "${navigator.userAgent}",
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
|
|
|
@ -41,10 +41,10 @@ add_task(async function () {
|
|||
const EXPECTED_REQUEST_HEADERS = [
|
||||
`${method} ${SIMPLE_URL.split("example.com")[1]} ${httpVersion}`,
|
||||
"Host: example.com",
|
||||
"User-Agent: " + navigator.userAgent + "",
|
||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
||||
"Accept-Language: " + navigator.languages.join(",") + ";q=0.5",
|
||||
"Accept-Encoding: gzip, deflate",
|
||||
"User-Agent: " + navigator.userAgent + "",
|
||||
"Connection: keep-alive",
|
||||
"Upgrade-Insecure-Requests: 1",
|
||||
"Pragma: no-cache",
|
||||
|
|
|
@ -134,10 +134,10 @@ async function verifyRawHeaders(monitor) {
|
|||
|
||||
const expectedRequestHeaders = [
|
||||
"Host",
|
||||
"User-Agent",
|
||||
"Accept",
|
||||
"Accept-Language",
|
||||
"Accept-Encoding",
|
||||
"User-Agent",
|
||||
"Connection",
|
||||
"Cookie",
|
||||
"Upgrade-Insecure-Requests",
|
||||
|
|
|
@ -18,12 +18,12 @@ add_task(async function () {
|
|||
await testConsoleInput(`await fetch("http://example.com/browser/devtools/client/netmonitor/test/sjs_simple-test-server.sjs", {
|
||||
"credentials": "omit",
|
||||
"headers": {
|
||||
"User-Agent": "${navigator.userAgent}",
|
||||
"Accept": "*/*",
|
||||
"Accept-Language": "en-US",
|
||||
"X-Custom-Header-1": "Custom value",
|
||||
"X-Custom-Header-2": "8.8.8.8",
|
||||
"X-Custom-Header-3": "Mon, 3 Mar 2014 11:11:11 GMT",
|
||||
"User-Agent": "${navigator.userAgent}",
|
||||
"Pragma": "no-cache",
|
||||
"Cache-Control": "no-cache"
|
||||
},
|
||||
|
|
|
@ -103,15 +103,18 @@ struct ParamTraits<mozilla::net::nsHttpHeaderArray::nsEntry> {
|
|||
case mozilla::net::nsHttpHeaderArray::eVarietyRequestDefault:
|
||||
WriteParam(aWriter, (uint8_t)2);
|
||||
break;
|
||||
case mozilla::net::nsHttpHeaderArray::
|
||||
eVarietyResponseNetOriginalAndResponse:
|
||||
case mozilla::net::nsHttpHeaderArray::eVarietyRequestEnforceDefault:
|
||||
WriteParam(aWriter, (uint8_t)3);
|
||||
break;
|
||||
case mozilla::net::nsHttpHeaderArray::eVarietyResponseNetOriginal:
|
||||
case mozilla::net::nsHttpHeaderArray::
|
||||
eVarietyResponseNetOriginalAndResponse:
|
||||
WriteParam(aWriter, (uint8_t)4);
|
||||
break;
|
||||
case mozilla::net::nsHttpHeaderArray::eVarietyResponse:
|
||||
case mozilla::net::nsHttpHeaderArray::eVarietyResponseNetOriginal:
|
||||
WriteParam(aWriter, (uint8_t)5);
|
||||
break;
|
||||
case mozilla::net::nsHttpHeaderArray::eVarietyResponse:
|
||||
WriteParam(aWriter, (uint8_t)6);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,14 +144,18 @@ struct ParamTraits<mozilla::net::nsHttpHeaderArray::nsEntry> {
|
|||
mozilla::net::nsHttpHeaderArray::eVarietyRequestDefault;
|
||||
break;
|
||||
case 3:
|
||||
aResult->variety =
|
||||
mozilla::net::nsHttpHeaderArray::eVarietyRequestEnforceDefault;
|
||||
break;
|
||||
case 4:
|
||||
aResult->variety = mozilla::net::nsHttpHeaderArray::
|
||||
eVarietyResponseNetOriginalAndResponse;
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
aResult->variety =
|
||||
mozilla::net::nsHttpHeaderArray::eVarietyResponseNetOriginal;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
aResult->variety = mozilla::net::nsHttpHeaderArray::eVarietyResponse;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -6141,14 +6141,11 @@ nsHttpChannel::AsyncOpen(nsIStreamListener* aListener) {
|
|||
// Note that we don't recalculate the header if it has been modified since the
|
||||
// channel was created because we want to preserve the modified header.
|
||||
if (!LoadIsUserAgentHeaderModified()) {
|
||||
rv = mRequestHead.ClearHeader(nsHttp::User_Agent);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
rv = mRequestHead.SetHeader(
|
||||
nsHttp::User_Agent,
|
||||
gHttpHandler->UserAgent(nsContentUtils::ShouldResistFingerprinting(
|
||||
this, RFPTarget::HttpUserAgent)),
|
||||
false, nsHttpHeaderArray::eVarietyRequestDefault);
|
||||
false, nsHttpHeaderArray::eVarietyRequestEnforceDefault);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ nsresult nsHttpHeaderArray::SetHeader(
|
|||
nsHttpHeaderArray::HeaderVariety variety) {
|
||||
MOZ_ASSERT(
|
||||
(variety == eVarietyResponse) || (variety == eVarietyRequestDefault) ||
|
||||
(variety == eVarietyRequestOverride),
|
||||
(variety == eVarietyRequestOverride) ||
|
||||
(variety == eVarietyRequestEnforceDefault),
|
||||
"Net original headers can only be set using SetHeader_internal().");
|
||||
|
||||
nsEntry* entry = nullptr;
|
||||
|
@ -61,8 +62,14 @@ nsresult nsHttpHeaderArray::SetHeader(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!entry || variety != eVarietyRequestDefault,
|
||||
MOZ_ASSERT((variety == eVarietyRequestEnforceDefault) ||
|
||||
(!entry || variety != eVarietyRequestDefault),
|
||||
"Cannot set default entry which overrides existing entry!");
|
||||
|
||||
// Set the variety to default if we are enforcing it.
|
||||
if (variety == eVarietyRequestEnforceDefault) {
|
||||
variety = eVarietyRequestDefault;
|
||||
}
|
||||
if (!entry) {
|
||||
return SetHeader_internal(header, headerName, value, variety);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ class nsHttpHeaderArray {
|
|||
// Used only for request header.
|
||||
eVarietyRequestOverride,
|
||||
eVarietyRequestDefault,
|
||||
eVarietyRequestEnforceDefault,
|
||||
// Used only for response header.
|
||||
eVarietyResponseNetOriginalAndResponse,
|
||||
eVarietyResponseNetOriginal,
|
||||
|
|
Загрузка…
Ссылка в новой задаче