aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-10-16 09:21:22 -0400
committerGitHub <noreply@github.com>2018-10-16 09:21:22 -0400
commitaa9591137a0a583c4b4718f4038545a860fbaeee (patch)
treeda81a9d552534b1c3e8cc7a784c0fde82a9eed86
parenta77ad4288ceda844d99e47fc89e0cd05bd01bd85 (diff)
parent65016d10e9b99eb4e34ca310e8083b233f389d64 (diff)
downloadservo-aa9591137a0a583c4b4718f4038545a860fbaeee.tar.gz
servo-aa9591137a0a583c4b4718f4038545a860fbaeee.zip
Auto merge of #21933 - notriddle:navigation-redirect-status-code, r=nox
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. --- <!-- 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 are part of #21886, but more changes are needed to actually fix it <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21933) <!-- Reviewable:end -->
-rw-r--r--components/constellation/network_listener.rs3
-rw-r--r--components/net_traits/response.rs2
-rw-r--r--tests/wpt/metadata/MANIFEST.json19
-rw-r--r--tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post-handler.py13
-rw-r--r--tests/wpt/web-platform-tests/fetch/redirect-navigate/302-found-post.html20
5 files changed, 57 insertions, 0 deletions
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<ServoUrl>,
pub location_url: Option<Result<ServoUrl, String>>,
}
@@ -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
}
diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json
index 29bf804b1d9..8a1d43ea750 100644
--- a/tests/wpt/metadata/MANIFEST.json
+++ b/tests/wpt/metadata/MANIFEST.json
@@ -283001,6 +283001,11 @@
{}
]
],
+ "fetch/redirect-navigate/302-found-post-handler.py": [
+ [
+ {}
+ ]
+ ],
"fetch/sec-metadata/README.md": [
[
{}
@@ -359258,6 +359263,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",
@@ -601413,6 +601424,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 @@
+<!DOCTYPE html>
+<!-- Step 1: send POST request to a URL which will then 302 Found redirect -->
+<title>HTTP 302 Found POST Navigation Test</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+async_test(function(t) {
+ window.addEventListener("load", function() {
+ var frame = document.getElementById("frame");
+ var link = new URL("302-found-post-handler.py", window.location.href);
+ frame.contentWindow.document.body.innerHTML = '<form action="' + link.href + '" method="POST" id="form"><input name="n"></form>';
+ frame.contentWindow.document.getElementById("form").submit();
+ frame.addEventListener("load", t.step_func_done(function() {
+ assert_equals(frame.contentWindow.document.body.textContent, "OK");
+ }));
+ });
+}, "HTTP 302 Found POST Navigation");
+</script>
+<body>
+<iframe id="frame" src="about:blank"></iframe>