From 3b1bfa3942f4e9c9b3649871ecd1655a1fc77736 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 13 Oct 2018 00:14:56 +0000 Subject: [PATCH 1/2] Thread the status through navigation redirects This is necessary because status codes affect whether the redirect is done with the same HTTP method or a different one. This is part of #21886, but there's also a flaw in how iframes are handled that is causing the redirect to take over the entire window, so this commit doesn't entirely fix slither.io. --- components/constellation/network_listener.rs | 3 +++ components/net_traits/response.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/components/constellation/network_listener.rs b/components/constellation/network_listener.rs index 461be7990da..3f58d029acf 100644 --- a/components/constellation/network_listener.rs +++ b/components/constellation/network_listener.rs @@ -113,6 +113,9 @@ impl NetworkListener { location_url: metadata.location_url.clone(), headers: headers.clone().into_inner(), referrer: metadata.referrer.clone(), + status_code: metadata.status.as_ref() + .map(|&(code, _)| code) + .unwrap_or(200), }); // XXXManishearth we don't have the cancel_chan anymore and diff --git a/components/net_traits/response.rs b/components/net_traits/response.rs index 3e2b7d0ad33..76278db19c7 100644 --- a/components/net_traits/response.rs +++ b/components/net_traits/response.rs @@ -82,6 +82,7 @@ pub struct ResponseInit { serialize_with = "::hyper_serde::serialize")] #[ignore_malloc_size_of = "Defined in hyper"] pub headers: Headers, + pub status_code: u16, pub referrer: Option, pub location_url: Option>, } @@ -147,6 +148,7 @@ impl Response { res.location_url = init.location_url; res.headers = init.headers; res.referrer = init.referrer; + res.status = Some(StatusCode::from_u16(init.status_code)); res } From 65016d10e9b99eb4e34ca310e8083b233f389d64 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 15 Oct 2018 06:01:09 +0000 Subject: [PATCH 2/2] Add WPT test for 302 Found --- tests/wpt/metadata/MANIFEST.json | 19 ++++++++++++++++++ .../302-found-post-handler.py | 13 ++++++++++++ .../redirect-navigate/302-found-post.html | 20 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post-handler.py create mode 100644 tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post.html diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 0c8f8380459..592a46c30c7 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -282894,6 +282894,11 @@ {} ] ], + "fetch/redirect-navigate/302-found-post-handler.py": [ + [ + {} + ] + ], "fetch/sec-metadata/README.md": [ [ {} @@ -359037,6 +359042,12 @@ {} ] ], + "fetch/redirect-navigate/302-found-post.html": [ + [ + "/fetch/redirect-navigate/302-found-post.html", + {} + ] + ], "fetch/sec-metadata/embed.tentative.https.sub.html": [ [ "/fetch/sec-metadata/embed.tentative.https.sub.html", @@ -601108,6 +601119,14 @@ "faaee86734e93bb514095e34671a57e00bcbcd98", "testharness" ], + "fetch/redirect-navigate/302-found-post-handler.py": [ + "23bf4b2c522b7c00ab6bd0fc3eb99f0737d512ec", + "support" + ], + "fetch/redirect-navigate/302-found-post.html": [ + "854cd329a8f12052bb79f35dd80268f246a52afd", + "testharness" + ], "fetch/sec-metadata/README.md": [ "c460aa1ecb941118b6999209ba4601eb145a61b9", "support" diff --git a/tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post-handler.py b/tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post-handler.py new file mode 100644 index 00000000000..23bf4b2c522 --- /dev/null +++ b/tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post-handler.py @@ -0,0 +1,13 @@ +def main(request, response): + if request.method == "POST": + response.add_required_headers = False + response.writer.write_status(302) + response.writer.write_header("Location", request.url) + response.writer.end_headers() + response.writer.write("") + elif request.method == "GET": + return ([("Content-Type", "text/plain")], + "OK") + else: + return ([("Content-Type", "text/plain")], + "FAIL") \ No newline at end of file diff --git a/tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post.html b/tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post.html new file mode 100644 index 00000000000..854cd329a8f --- /dev/null +++ b/tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post.html @@ -0,0 +1,20 @@ + + +HTTP 302 Found POST Navigation Test + + + + +