Skip to content

Commit

Permalink
Fix the redirected attribute for Response
Browse files Browse the repository at this point in the history
  • Loading branch information
Eijebong committed May 5, 2020
1 parent 566147d commit aa43ce8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 66 deletions.
3 changes: 3 additions & 0 deletions components/net_traits/lib.rs
Expand Up @@ -638,6 +638,8 @@ pub struct Metadata {
pub referrer_policy: Option<ReferrerPolicy>,
/// Performance information for navigation events
pub timing: Option<ResourceFetchTiming>,
/// True if the request comes from a redirection
pub redirected: bool,
}

impl Metadata {
Expand All @@ -655,6 +657,7 @@ impl Metadata {
referrer: None,
referrer_policy: None,
timing: None,
redirected: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions components/net_traits/response.rs
Expand Up @@ -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
};

Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/response.rs
Expand Up @@ -51,6 +51,7 @@ pub struct Response {
body_promise: DomRefCell<Option<(Rc<Promise>, BodyType)>>,
#[ignore_malloc_size_of = "StreamConsumer"]
stream_consumer: DomRefCell<Option<StreamConsumer>>,
redirected: DomRefCell<bool>,
}

#[allow(non_snake_case)]
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions components/script/fetch.rs
Expand Up @@ -306,6 +306,7 @@ fn fill_headers_with_metadata(r: DomRoot<Response>, 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.
Expand Down
66 changes: 0 additions & 66 deletions 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

0 comments on commit aa43ce8

Please sign in to comment.