mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
fetch: header tweaks to improve compliance with fetch spec (#33562)
* fetch: various header tweaks to improve compliance with fetch spec Signed-off-by: Shane Handley <shanehandley@fastmail.com> * fix: simplify the authorization header removal Signed-off-by: Shane Handley <shanehandley@fastmail.com> --------- Signed-off-by: Shane Handley <shanehandley@fastmail.com>
This commit is contained in:
parent
f96a62f0ce
commit
c7ef974968
12 changed files with 21 additions and 61 deletions
|
@ -25,7 +25,8 @@ use headers::{
|
||||||
IfModifiedSince, LastModified, Origin as HyperOrigin, Pragma, Referer, UserAgent,
|
IfModifiedSince, LastModified, Origin as HyperOrigin, Pragma, Referer, UserAgent,
|
||||||
};
|
};
|
||||||
use http::header::{
|
use http::header::{
|
||||||
self, HeaderValue, ACCEPT, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LOCATION, CONTENT_TYPE,
|
self, HeaderValue, ACCEPT, AUTHORIZATION, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LOCATION,
|
||||||
|
CONTENT_TYPE,
|
||||||
};
|
};
|
||||||
use http::{HeaderMap, Method, Request as HyperRequest, StatusCode};
|
use http::{HeaderMap, Method, Request as HyperRequest, StatusCode};
|
||||||
use hyper::header::{HeaderName, TRANSFER_ENCODING};
|
use hyper::header::{HeaderName, TRANSFER_ENCODING};
|
||||||
|
@ -1030,15 +1031,27 @@ pub async fn http_redirect_fetch(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 12
|
// Step 13: If request’s current URL’s origin is not same origin with locationURL’s origin, then
|
||||||
|
// for each headerName of CORS non-wildcard request-header name, delete headerName from
|
||||||
|
// request’s header list.
|
||||||
|
if location_url.origin() != request.current_url().origin() {
|
||||||
|
// This list currently only contains the AUTHORIZATION header
|
||||||
|
// https://fetch.spec.whatwg.org/#cors-non-wildcard-request-header-name
|
||||||
|
request.headers.remove(AUTHORIZATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 14: If request’s body is non-null, then set request’s body to the body of the result of
|
||||||
|
// safely extracting request’s body’s source.
|
||||||
if let Some(body) = request.body.as_mut() {
|
if let Some(body) = request.body.as_mut() {
|
||||||
body.extract_source();
|
body.extract_source();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 13
|
// Steps 15-17 relate to timing, which is not implemented 1:1 with the spec.
|
||||||
|
|
||||||
|
// Step 18: Append locationURL to request’s URL list.
|
||||||
request.url_list.push(location_url);
|
request.url_list.push(location_url);
|
||||||
|
|
||||||
// Step 14
|
// Step 19: Invoke set request’s referrer policy on redirect on request and internalResponse.
|
||||||
if let Some(referrer_policy) = response
|
if let Some(referrer_policy) = response
|
||||||
.actual_response()
|
.actual_response()
|
||||||
.headers
|
.headers
|
||||||
|
@ -1047,9 +1060,11 @@ pub async fn http_redirect_fetch(
|
||||||
request.referrer_policy = Some(referrer_policy.into());
|
request.referrer_policy = Some(referrer_policy.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 15
|
// Step 20: Let recursive be true.
|
||||||
|
// Step 21: If request’s redirect mode is "manual", then...
|
||||||
let recursive_flag = request.redirect_mode != RedirectMode::Manual;
|
let recursive_flag = request.redirect_mode != RedirectMode::Manual;
|
||||||
|
|
||||||
|
// Step 22: Return the result of running main fetch given fetchParams and recursive.
|
||||||
let fetch_response = main_fetch(
|
let fetch_response = main_fetch(
|
||||||
request,
|
request,
|
||||||
cache,
|
cache,
|
||||||
|
|
|
@ -267,7 +267,7 @@ impl Response {
|
||||||
ResponseType::Cors => {
|
ResponseType::Cors => {
|
||||||
let headers = old_headers.iter().filter(|(name, _)| {
|
let headers = old_headers.iter().filter(|(name, _)| {
|
||||||
match &*name.as_str().to_ascii_lowercase() {
|
match &*name.as_str().to_ascii_lowercase() {
|
||||||
"cache-control" | "content-language" | "content-type" |
|
"cache-control" | "content-language" | "content-length" | "content-type" |
|
||||||
"expires" | "last-modified" | "pragma" => true,
|
"expires" | "last-modified" | "pragma" => true,
|
||||||
"set-cookie" | "set-cookie2" => false,
|
"set-cookie" | "set-cookie2" => false,
|
||||||
header => {
|
header => {
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
[response-headers.htm]
|
|
||||||
[getResponseHeader: Content-Length: readable by default]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
[cors-filtering.sub.any.html]
|
|
||||||
[CORS filter on Content-Length header]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[cors-filtering.sub.any.worker.html]
|
|
||||||
[CORS filter on Content-Length header]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
[authentication-redirection.any.html]
|
[authentication-redirection.any.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[authentication-redirection.any.worker.html]
|
[authentication-redirection.any.worker.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[authentication-redirection.any.sharedworker.html]
|
[authentication-redirection.any.sharedworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
[access-control-basic-cors-safelisted-response-headers.htm]
|
|
||||||
[Response with CORS-safelisted headers]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -2,13 +2,8 @@
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[xhr-authorization-redirect.any.html]
|
[xhr-authorization-redirect.any.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[xhr-authorization-redirect.any.serviceworker.html]
|
[xhr-authorization-redirect.any.serviceworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[xhr-authorization-redirect.any.worker.html]
|
[xhr-authorization-redirect.any.worker.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
4
tests/wpt/meta/cors/response-headers.htm.ini
vendored
4
tests/wpt/meta/cors/response-headers.htm.ini
vendored
|
@ -1,4 +0,0 @@
|
||||||
[response-headers.htm]
|
|
||||||
[getResponseHeader: Content-Length: readable by default]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
[cors-filtering.sub.any.html]
|
|
||||||
[CORS filter on Content-Length header]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[cors-filtering.sub.any.worker.html]
|
|
||||||
[CORS filter on Content-Length header]
|
|
||||||
expected: FAIL
|
|
|
@ -2,13 +2,8 @@
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[authentication-redirection.any.html]
|
[authentication-redirection.any.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[authentication-redirection.any.serviceworker.html]
|
[authentication-redirection.any.serviceworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[authentication-redirection.any.worker.html]
|
[authentication-redirection.any.worker.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
[access-control-basic-cors-safelisted-response-headers.htm]
|
|
||||||
[Response with CORS-safelisted headers]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -2,14 +2,8 @@
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[xhr-authorization-redirect.any.worker.html]
|
[xhr-authorization-redirect.any.worker.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[xhr-authorization-redirect.any.html]
|
[xhr-authorization-redirect.any.html]
|
||||||
[getAuthorizationHeaderValue - cross origin redirection]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[xhr-authorization-redirect.any.serviceworker.html]
|
[xhr-authorization-redirect.any.serviceworker.html]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue