servo: Merge #13561 - Make Request throw less often (fixes #13457) (from mathieuh:request-constructor); r=jdm
authorMathieu Hordesseaux <mathieu@adopteunmec.com>
Thu, 23 Feb 2017 17:54:40 -0800
changeset 373578 798f55990ad17da87c774d62dfa91e2bced3ab81
parent 373577 9a85f428c314cbbe0bae36f8fd1402373bdc7f71
child 373579 baff63f434f73b9b70aff0fbbcad42ed7c777f71
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
milestone54.0a1
servo: Merge #13561 - Make Request throw less often (fixes #13457) (from mathieuh:request-constructor); r=jdm <!-- 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. --> Source-Repo: https://github.com/servo/servo Source-Revision: 3bf81c389bf8ddfce7c862cdd112ed0a85a91529
servo/components/script/dom/request.rs
--- a/servo/components/script/dom/request.rs
+++ b/servo/components/script/dom/request.rs
@@ -178,19 +178,18 @@ impl Request {
             init.method.is_some() ||
             init.mode.is_some() ||
             init.redirect.is_some() ||
             init.referrer.is_some() ||
             init.referrerPolicy.is_some() ||
             !init.window.handle().is_undefined() {
                 // Step 13.1
                 if request.mode == NetTraitsRequestMode::Navigate {
-                    return Err(Error::Type(
-                        "Init is present and request mode is 'navigate'".to_string()));
-                    }
+                    request.mode = NetTraitsRequestMode::SameOrigin;
+                }
                 // Step 13.2
                 request.omit_origin_header.set(false);
                 // Step 13.3
                 *request.referrer.borrow_mut() = NetTraitsRequestReferrer::Client;
                 // Step 13.4
                 request.referrer_policy.set(None);
             }
 
@@ -206,27 +205,23 @@ impl Request {
                 let parsed_referrer = base_url.join(referrer);
                 // Step 14.4
                 if parsed_referrer.is_err() {
                     return Err(Error::Type(
                         "Failed to parse referrer url".to_string()));
                 }
                 // Step 14.5
                 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.path() == "client" {
+                        parsed_referrer.path() == "client") ||
+                       parsed_referrer.origin() != origin {
                             *request.referrer.borrow_mut() = NetTraitsRequestReferrer::Client;
                         } else {
                             // 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);
                         }
                 }
             }
         }
 
         // Step 15
         if let Some(init_referrerpolicy) = init.referrerPolicy.as_ref() {
@@ -571,17 +566,17 @@ impl RequestMethods for Request {
     }
 
     // https://fetch.spec.whatwg.org/#dom-request-referrer
     fn Referrer(&self) -> USVString {
         let r = self.request.borrow();
         let referrer = r.referrer.borrow();
         USVString(match &*referrer {
             &NetTraitsRequestReferrer::NoReferrer => String::from("no-referrer"),
-            &NetTraitsRequestReferrer::Client => String::from("client"),
+            &NetTraitsRequestReferrer::Client => String::from("about:client"),
             &NetTraitsRequestReferrer::ReferrerUrl(ref u) => {
                 let u_c = u.clone();
                 u_c.into_string()
             }
         })
     }
 
     // https://fetch.spec.whatwg.org/#dom-request-referrerpolicy