mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 1188932 - Allow the User-Agent header to be explicitly set by requests, r=bkelly, r=jgraham
This commit is contained in:
parent
fb6ddae47f
commit
092e4a4b9e
@ -7188,7 +7188,7 @@ nsContentUtils::IsForbiddenSystemRequestHeader(const nsACString& aHeader)
|
||||
"access-control-request-method", "connection", "content-length",
|
||||
"cookie", "cookie2", "content-transfer-encoding", "date", "dnt",
|
||||
"expect", "host", "keep-alive", "origin", "referer", "te", "trailer",
|
||||
"transfer-encoding", "upgrade", "user-agent", "via"
|
||||
"transfer-encoding", "upgrade", "via"
|
||||
};
|
||||
for (uint32_t i = 0; i < ArrayLength(kInvalidHeaders); ++i) {
|
||||
if (aHeader.LowerCaseEqualsASCII(kInvalidHeaders[i])) {
|
||||
|
8
dom/base/test/file_explicit_user_agent.sjs
Normal file
8
dom/base/test/file_explicit_user_agent.sjs
Normal file
@ -0,0 +1,8 @@
|
||||
function handleRequest(request, response)
|
||||
{
|
||||
if (request.hasHeader("User-Agent")) {
|
||||
response.setHeader("Result-User-Agent",
|
||||
request.getHeader("User-Agent"));
|
||||
}
|
||||
response.write("");
|
||||
}
|
@ -253,6 +253,7 @@ support-files =
|
||||
test_performance_observer.js
|
||||
performance_observer.html
|
||||
test_anonymousContent_style_csp.html^headers^
|
||||
file_explicit_user_agent.sjs
|
||||
|
||||
[test_anonymousContent_api.html]
|
||||
[test_anonymousContent_append_after_reflow.html]
|
||||
@ -843,3 +844,4 @@ support-files = worker_postMessages.js
|
||||
[test_window_proto.html]
|
||||
[test_frameLoader_switchProcess.html]
|
||||
skip-if = e10s || os != 'linux' || buildapp != 'browser'
|
||||
[test_explicit_user_agent.html]
|
||||
|
65
dom/base/test/test_explicit_user_agent.html
Normal file
65
dom/base/test/test_explicit_user_agent.html
Normal file
@ -0,0 +1,65 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for XMLHttpRequest.GetResponseHeader(foo) byte-inflates the output</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
add_task(function*() {
|
||||
yield new Promise((r) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'file_explicit_user_agent.sjs', true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
is(xhr.getResponseHeader("Result-User-Agent"), navigator.userAgent,
|
||||
"The resulting user-agent is the navigator's UA");
|
||||
r();
|
||||
}
|
||||
}
|
||||
xhr.send(null);
|
||||
});
|
||||
|
||||
yield new Promise((r) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'file_explicit_user_agent.sjs', true);
|
||||
xhr.setRequestHeader('User-Agent', 'custom-ua/10.0');
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
is(xhr.getResponseHeader("Result-User-Agent"), 'custom-ua/10.0',
|
||||
"The resulting user-agent is the custom UA");
|
||||
r();
|
||||
}
|
||||
}
|
||||
xhr.send(null);
|
||||
});
|
||||
|
||||
var response = yield fetch('file_explicit_user_agent.sjs', {
|
||||
method: 'GET'
|
||||
});
|
||||
is(response.headers.get("Result-User-Agent"), navigator.userAgent,
|
||||
"The user-agent is the navigator's UA");
|
||||
|
||||
var headers = new Headers();
|
||||
headers.set('User-Agent', 'custom-ua/20.0');
|
||||
var response2 = yield fetch('file_explicit_user_agent.sjs', {
|
||||
method: 'GET',
|
||||
headers: headers,
|
||||
});
|
||||
is(response2.headers.get("Result-User-Agent"), 'custom-ua/20.0',
|
||||
"The user-agent is the custom UA");
|
||||
});
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -40,7 +40,6 @@ var headers = [
|
||||
"trAiLer",
|
||||
"trANsfEr-eNcoDiNg",
|
||||
"uPGraDe",
|
||||
"user-AGENT",
|
||||
"viA",
|
||||
"pRoxy-",
|
||||
"sEc-",
|
||||
|
@ -165,6 +165,15 @@ function runTest() {
|
||||
headers: { "myheader": "" },
|
||||
allowMethods: "myheader",
|
||||
},
|
||||
{ pass: 1,
|
||||
method: "GET",
|
||||
headers: { "User-Agent": "myValue" },
|
||||
allowHeaders: "User-Agent",
|
||||
},
|
||||
{ pass: 0,
|
||||
method: "GET",
|
||||
headers: { "User-Agent": "myValue" },
|
||||
},
|
||||
|
||||
// Multiple custom headers
|
||||
{ pass: 1,
|
||||
|
@ -264,6 +264,15 @@ function testModeCors() {
|
||||
headers: { "myheader": "" },
|
||||
allowMethods: "myheader",
|
||||
},
|
||||
{ pass: 1,
|
||||
method: "GET",
|
||||
headers: { "User-Agent": "myValue" },
|
||||
allowHeaders: "User-Agent",
|
||||
},
|
||||
{ pass: 0,
|
||||
method: "GET",
|
||||
headers: { "User-Agent": "myValue" },
|
||||
},
|
||||
|
||||
// Multiple custom headers
|
||||
{ pass: 1,
|
||||
|
@ -39,7 +39,6 @@ function TestRequestHeaders() {
|
||||
"Trailer",
|
||||
"Transfer-Encoding",
|
||||
"Upgrade",
|
||||
"User-Agent",
|
||||
"Via",
|
||||
"Proxy-Authorization",
|
||||
"Proxy-blarg",
|
||||
|
@ -1,5 +0,0 @@
|
||||
[preserve-ua-header-on-redirect.htm]
|
||||
type: testharness
|
||||
[XMLHttpRequest: User-Agent header is preserved on redirect 1]
|
||||
expected: FAIL
|
||||
|
Loading…
Reference in New Issue
Block a user