Auto merge of #13561 - mathieuh:request-constructor, r=jdm

Make Request throw less often (fixes #13457)

<!-- Please describe your changes on the following line: -->

---

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #13457

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->

---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13561)

<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-23 17:54:40 -08:00 committed by GitHub
commit 3bf81c389b
6 changed files with 15 additions and 29 deletions

View file

@ -183,9 +183,8 @@ impl Request {
!init.window.handle().is_undefined() { !init.window.handle().is_undefined() {
// Step 13.1 // Step 13.1
if request.mode == NetTraitsRequestMode::Navigate { if request.mode == NetTraitsRequestMode::Navigate {
return Err(Error::Type( request.mode = NetTraitsRequestMode::SameOrigin;
"Init is present and request mode is 'navigate'".to_string())); }
}
// Step 13.2 // Step 13.2
request.omit_origin_header.set(false); request.omit_origin_header.set(false);
// Step 13.3 // Step 13.3
@ -211,17 +210,13 @@ impl Request {
} }
// Step 14.5 // Step 14.5
if let Ok(parsed_referrer) = parsed_referrer { if let Ok(parsed_referrer) = parsed_referrer {
if parsed_referrer.cannot_be_a_base() && if (parsed_referrer.cannot_be_a_base() &&
parsed_referrer.scheme() == "about" && parsed_referrer.scheme() == "about" &&
parsed_referrer.path() == "client" { parsed_referrer.path() == "client") ||
parsed_referrer.origin() != origin {
*request.referrer.borrow_mut() = NetTraitsRequestReferrer::Client; *request.referrer.borrow_mut() = NetTraitsRequestReferrer::Client;
} else { } else {
// Step 14.6 // Step 14.6
if parsed_referrer.origin() != origin {
return Err(Error::Type(
"RequestInit's referrer has invalid origin".to_string()));
}
// Step 14.7
*request.referrer.borrow_mut() = NetTraitsRequestReferrer::ReferrerUrl(parsed_referrer); *request.referrer.borrow_mut() = NetTraitsRequestReferrer::ReferrerUrl(parsed_referrer);
} }
} }
@ -576,7 +571,7 @@ impl RequestMethods for Request {
let referrer = r.referrer.borrow(); let referrer = r.referrer.borrow();
USVString(match &*referrer { USVString(match &*referrer {
&NetTraitsRequestReferrer::NoReferrer => String::from("no-referrer"), &NetTraitsRequestReferrer::NoReferrer => String::from("no-referrer"),
&NetTraitsRequestReferrer::Client => String::from("client"), &NetTraitsRequestReferrer::Client => String::from("about:client"),
&NetTraitsRequestReferrer::ReferrerUrl(ref u) => { &NetTraitsRequestReferrer::ReferrerUrl(ref u) => {
let u_c = u.clone(); let u_c = u.clone();
u_c.into_string() u_c.into_string()

View file

@ -164191,7 +164191,7 @@
"testharness" "testharness"
], ],
"fetch/api/request/request-error.html": [ "fetch/api/request/request-error.html": [
"bfd03777a43be514a0839ab14f5206f486332fdb", "ff308916884f69b3f4aa8f2017c4d9fe0caf0f00",
"testharness" "testharness"
], ],
"fetch/api/request/request-headers.html": [ "fetch/api/request/request-headers.html": [
@ -164203,7 +164203,7 @@
"testharness" "testharness"
], ],
"fetch/api/request/request-init-001.sub.html": [ "fetch/api/request/request-init-001.sub.html": [
"096424b40f6a21e989a6a5d8684b29ee8cbb963e", "49bc4349b4e7a85d88cacd54227355aa986535f1",
"testharness" "testharness"
], ],
"fetch/api/request/request-init-002.html": [ "fetch/api/request/request-init-002.html": [

View file

@ -1,20 +1,10 @@
[request-init-001.sub.html] [request-init-001.sub.html]
type: testharness type: testharness
[Check referrer init value of about:client and associated getter]
expected: FAIL
[Check referrer init value of and associated getter] [Check referrer init value of and associated getter]
expected: FAIL expected: FAIL
[Check referrerPolicy init value of and associated getter] [Check referrerPolicy init value of and associated getter]
expected: FAIL expected: FAIL
[Check referrer init value of http://test.url and associated getter]
expected: FAIL
[Check referrerPolicy init value of same-origin and associated getter] [Check referrerPolicy init value of same-origin and associated getter]
expected: FAIL expected: FAIL
[Check mode init value of navigate and associated getter]
expected: FAIL

View file

@ -2,7 +2,3 @@
type: testharness type: testharness
[Request has arrayBuffer method] [Request has arrayBuffer method]
expected: FAIL expected: FAIL
[Check referrer attribute]
expected: FAIL

View file

@ -26,6 +26,11 @@
"Expect TypeError exception"); "Expect TypeError exception");
},"Input URL has credentials"); },"Input URL has credentials");
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"mode" : "navigate"}); },
"Expect TypeError exception");
},"RequestInit's mode is navigate");
test(function() { test(function() {
assert_throws(new TypeError() , function() { new Request("", {"referrer" : "http://:not a valid URL"}); }, assert_throws(new TypeError() , function() { new Request("", {"referrer" : "http://:not a valid URL"}); },
"Expect TypeError exception"); "Expect TypeError exception");

View file

@ -49,8 +49,8 @@
"strict-origin-when-cross-origin" "strict-origin-when-cross-origin"
] ]
}; };
var modes = {"givenValues" : ["same-origin", "no-cors", "cors", "navigate"], var modes = {"givenValues" : ["same-origin", "no-cors", "cors"],
"expectedValues" : ["same-origin", "no-cors", "cors", "same-origin"] "expectedValues" : ["same-origin", "no-cors", "cors"]
}; };
var credentials = {"givenValues" : ["omit", "same-origin", "include"], var credentials = {"givenValues" : ["omit", "same-origin", "include"],
"expectedValues" : ["omit", "same-origin", "include"] "expectedValues" : ["omit", "same-origin", "include"]