From aa43ce8cf32b2f44d58145df9198c36091aac5e1 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 21 Dec 2019 15:09:53 +0100 Subject: [PATCH] Fix the redirected attribute for Response --- components/net_traits/lib.rs | 3 + components/net_traits/response.rs | 1 + components/script/dom/response.rs | 6 ++ components/script/fetch.rs | 1 + .../api/redirect/redirect-method.any.js.ini | 66 ------------------- 5 files changed, 11 insertions(+), 66 deletions(-) diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 2de544c31fe..a7100e0ef44 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -638,6 +638,8 @@ pub struct Metadata { pub referrer_policy: Option, /// Performance information for navigation events pub timing: Option, + /// True if the request comes from a redirection + pub redirected: bool, } impl Metadata { @@ -655,6 +657,7 @@ impl Metadata { referrer: None, referrer_policy: None, timing: None, + redirected: false, } } diff --git a/components/net_traits/response.rs b/components/net_traits/response.rs index 34e46ebc6a3..f509801678f 100644 --- a/components/net_traits/response.rs +++ b/components/net_traits/response.rs @@ -310,6 +310,7 @@ impl Response { metadata.https_state = response.https_state; metadata.referrer = response.referrer.clone(); metadata.referrer_policy = response.referrer_policy.clone(); + metadata.redirected = response.actual_response().url_list.len() > 1; metadata }; diff --git a/components/script/dom/response.rs b/components/script/dom/response.rs index e605edeac2c..d04cde07755 100644 --- a/components/script/dom/response.rs +++ b/components/script/dom/response.rs @@ -51,6 +51,7 @@ pub struct Response { body_promise: DomRefCell, BodyType)>>, #[ignore_malloc_size_of = "StreamConsumer"] stream_consumer: DomRefCell>, + redirected: DomRefCell, } #[allow(non_snake_case)] @@ -69,6 +70,7 @@ impl Response { body: DomRefCell::new(NetTraitsResponseBody::Empty), body_promise: DomRefCell::new(None), stream_consumer: DomRefCell::new(None), + redirected: DomRefCell::new(false), } } @@ -414,6 +416,10 @@ impl Response { *self.url.borrow_mut() = Some(final_url); } + pub fn set_redirected(&self, is_redirected: bool) { + *self.redirected.borrow_mut() = is_redirected; + } + fn set_response_members_by_type(&self, response_type: DOMResponseType) { match response_type { DOMResponseType::Error => { diff --git a/components/script/fetch.rs b/components/script/fetch.rs index 66b5ee3c6ef..fe0792d857f 100644 --- a/components/script/fetch.rs +++ b/components/script/fetch.rs @@ -306,6 +306,7 @@ fn fill_headers_with_metadata(r: DomRoot, m: Metadata) { r.set_headers(m.headers); r.set_raw_status(m.status); r.set_final_url(m.final_url); + r.set_redirected(m.redirected); } /// Convenience function for synchronously loading a whole resource. diff --git a/tests/wpt/metadata/fetch/api/redirect/redirect-method.any.js.ini b/tests/wpt/metadata/fetch/api/redirect/redirect-method.any.js.ini index 0b6787710cf..e2d28b96134 100644 --- a/tests/wpt/metadata/fetch/api/redirect/redirect-method.any.js.ini +++ b/tests/wpt/metadata/fetch/api/redirect/redirect-method.any.js.ini @@ -1,87 +1,21 @@ [redirect-method.any.worker.html] - [Redirect 301 with GET] - expected: FAIL - - [Redirect 301 with POST] - expected: FAIL - - [Redirect 301 with HEAD] - expected: FAIL - - [Redirect 302 with GET] - expected: FAIL - - [Redirect 302 with POST] - expected: FAIL - - [Redirect 302 with HEAD] - expected: FAIL - [Redirect 303 with GET] expected: FAIL - [Redirect 303 with POST] - expected: FAIL - - [Redirect 303 with HEAD] - expected: FAIL - - [Redirect 307 with GET] - expected: FAIL - [Redirect 307 with POST (string body)] expected: FAIL [Redirect 307 with POST (blob body)] expected: FAIL - [Redirect 307 with HEAD] - expected: FAIL - - [Redirect 303 with TESTING] - expected: FAIL - [redirect-method.any.html] - [Redirect 301 with GET] - expected: FAIL - - [Redirect 301 with POST] - expected: FAIL - - [Redirect 301 with HEAD] - expected: FAIL - - [Redirect 302 with GET] - expected: FAIL - - [Redirect 302 with POST] - expected: FAIL - - [Redirect 302 with HEAD] - expected: FAIL - [Redirect 303 with GET] expected: FAIL - [Redirect 303 with POST] - expected: FAIL - - [Redirect 303 with HEAD] - expected: FAIL - - [Redirect 307 with GET] - expected: FAIL - [Redirect 307 with POST (string body)] expected: FAIL [Redirect 307 with POST (blob body)] expected: FAIL - [Redirect 307 with HEAD] - expected: FAIL - - [Redirect 303 with TESTING] - expected: FAIL -