From 566147dab3d15dac82533668de2f92026ad52ff5 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 21 Dec 2019 13:40:39 +0100 Subject: [PATCH] Strip request-body-header when redirecting from a POST to GET This doesn't change any expectation because we're not setting response.redirected properly so all the tests fail later on when it's asserted to be true. Fixes #25257 --- components/net/http_loader.rs | 15 ++++++++++++++- components/script/dom/response.rs | 3 +-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 18dff8ca0ef..10c2d7faaec 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -25,7 +25,10 @@ use headers::{ use headers::{AccessControlAllowOrigin, AccessControlMaxAge}; use headers::{CacheControl, ContentEncoding, ContentLength}; use headers::{IfModifiedSince, LastModified, Origin as HyperOrigin, Pragma, Referer, UserAgent}; -use http::header::{self, HeaderName, HeaderValue}; +use http::header::{ + self, HeaderName, HeaderValue, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LOCATION, + CONTENT_TYPE, +}; use http::{HeaderMap, Request as HyperRequest}; use hyper::{Body, Client, Method, Response as HyperResponse, StatusCode}; use hyper_serde::Serde; @@ -804,8 +807,18 @@ pub fn http_redirect_fetch( (*code == StatusCode::SEE_OTHER && request.method != Method::HEAD) }) { + // Step 11.1 request.method = Method::GET; request.body = None; + // Step 11.2 + for name in &[ + CONTENT_ENCODING, + CONTENT_LANGUAGE, + CONTENT_LOCATION, + CONTENT_TYPE, + ] { + request.headers.remove(name); + } } // Step 12 diff --git a/components/script/dom/response.rs b/components/script/dom/response.rs index 636acc05ff5..e605edeac2c 100644 --- a/components/script/dom/response.rs +++ b/components/script/dom/response.rs @@ -287,8 +287,7 @@ impl ResponseMethods for Response { // https://fetch.spec.whatwg.org/#dom-response-redirected fn Redirected(&self) -> bool { - let url_list_len = self.url_list.borrow().len(); - url_list_len > 1 + return *self.redirected.borrow(); } // https://fetch.spec.whatwg.org/#dom-response-status