servo: Merge #14496 - Stop handling a None referrer policy in determine_request_referrer() (from servo:option-refpol); r=KiChjang
authorMs2ger <Ms2ger@gmail.com>
Thu, 08 Dec 2016 11:52:35 -0800
changeset 340297 6e19e0cad42c3862e0214dbe8bc76029a8cfc964
parent 340296 7001118ad67bd4f7fdd51bfc91aa05f4f2abb8d9
child 340298 81364670e29057d38aeea04189822f8dd45275b6
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersKiChjang
servo: Merge #14496 - Stop handling a None referrer policy in determine_request_referrer() (from servo:option-refpol); r=KiChjang Source-Repo: https://github.com/servo/servo Source-Revision: 1e3d4d272de53e77334b1c32d3e3737f935c4cde
servo/components/net/fetch/methods.rs
servo/components/net/http_loader.rs
--- a/servo/components/net/fetch/methods.rs
+++ b/servo/components/net/fetch/methods.rs
@@ -145,27 +145,26 @@ pub fn main_fetch(request: Rc<Request>,
     // Step 5
     // TODO this step (CSP port/content blocking)
 
     // Step 6
     // TODO this step (referrer policy)
     // currently the clients themselves set referrer policy in RequestInit
 
     // Step 7
-    if request.referrer_policy.get().is_none() {
-        request.referrer_policy.set(Some(ReferrerPolicy::NoReferrerWhenDowngrade));
-    }
+    let referrer_policy = request.referrer_policy.get().unwrap_or(ReferrerPolicy::NoReferrerWhenDowngrade);
+    request.referrer_policy.set(Some(referrer_policy));
 
     // Step 8
     if *request.referrer.borrow() != Referrer::NoReferrer {
         // remove Referrer headers set in past redirects/preflights
         // this stops the assertion in determine_request_referrer from failing
         request.headers.borrow_mut().remove::<RefererHeader>();
         let referrer_url = determine_request_referrer(&mut *request.headers.borrow_mut(),
-                                                      request.referrer_policy.get(),
+                                                      referrer_policy,
                                                       request.referrer.borrow_mut().take(),
                                                       request.current_url().clone());
         *request.referrer.borrow_mut() = Referrer::from_url(referrer_url);
     }
 
     // Step 9
     // TODO this step (HSTS)
 
--- a/servo/components/net/http_loader.rs
+++ b/servo/components/net/http_loader.rs
@@ -272,32 +272,32 @@ fn strip_url(mut referrer_url: ServoUrl,
         }
         return Some(referrer_url);
     }
     return None;
 }
 
 /// https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer
 pub fn determine_request_referrer(headers: &mut Headers,
-                                  referrer_policy: Option<ReferrerPolicy>,
+                                  referrer_policy: ReferrerPolicy,
                                   referrer_url: Option<ServoUrl>,
                                   url: ServoUrl) -> Option<ServoUrl> {
     //TODO - algorithm step 2 not addressed
     assert!(!headers.has::<Referer>());
     if let Some(ref_url) = referrer_url {
         let cross_origin = ref_url.origin() != url.origin();
         return match referrer_policy {
-            Some(ReferrerPolicy::NoReferrer) => None,
-            Some(ReferrerPolicy::Origin) => strip_url(ref_url, true),
-            Some(ReferrerPolicy::SameOrigin) => if cross_origin { None } else { strip_url(ref_url, false) },
-            Some(ReferrerPolicy::UnsafeUrl) => strip_url(ref_url, false),
-            Some(ReferrerPolicy::OriginWhenCrossOrigin) => strip_url(ref_url, cross_origin),
-            Some(ReferrerPolicy::StrictOrigin) => strict_origin(ref_url, url),
-            Some(ReferrerPolicy::StrictOriginWhenCrossOrigin) => strict_origin_when_cross_origin(ref_url, url),
-            Some(ReferrerPolicy::NoReferrerWhenDowngrade) | None =>
+            ReferrerPolicy::NoReferrer => None,
+            ReferrerPolicy::Origin => strip_url(ref_url, true),
+            ReferrerPolicy::SameOrigin => if cross_origin { None } else { strip_url(ref_url, false) },
+            ReferrerPolicy::UnsafeUrl => strip_url(ref_url, false),
+            ReferrerPolicy::OriginWhenCrossOrigin => strip_url(ref_url, cross_origin),
+            ReferrerPolicy::StrictOrigin => strict_origin(ref_url, url),
+            ReferrerPolicy::StrictOriginWhenCrossOrigin => strict_origin_when_cross_origin(ref_url, url),
+            ReferrerPolicy::NoReferrerWhenDowngrade =>
                 no_referrer_when_downgrade_header(ref_url, url),
         };
     }
     return None;
 }
 
 pub fn set_request_cookies(url: &ServoUrl, headers: &mut Headers, cookie_jar: &Arc<RwLock<CookieStorage>>) {
     let mut cookie_jar = cookie_jar.write().unwrap();