mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Fixes for HTTP header compliance. (#32024)
- Fix 400 errors from nginx in response to Servo requests by implementing conformant albeit non-normative removal of whitespace from `Accept` and `Accept-Language` HTTP headers. (To match behaviour of Firefox, Safari, and Chrome) https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2 - Provide `Host` header as REQUIRED by HTTP protocol https://www.rfc-editor.org/rfc/rfc9110#field.host - Update tests.
This commit is contained in:
parent
62a25fdcc4
commit
10ec8565ea
4 changed files with 44 additions and 24 deletions
|
@ -1225,7 +1225,20 @@ async fn http_network_or_cache_fetch(
|
|||
|
||||
// Step 5.16
|
||||
let current_url = http_request.current_url();
|
||||
http_request.headers.remove(header::HOST);
|
||||
if !http_request.headers.contains_key(header::HOST) {
|
||||
let host = if current_url.port().is_none() {
|
||||
current_url.host_str().unwrap().to_string()
|
||||
} else {
|
||||
format!(
|
||||
"{}:{}",
|
||||
current_url.host_str().unwrap(),
|
||||
current_url.port().unwrap()
|
||||
)
|
||||
};
|
||||
http_request.headers.typed_insert(headers::Host::from(
|
||||
host.parse::<http::uri::Authority>().unwrap(),
|
||||
));
|
||||
}
|
||||
|
||||
// unlike http_loader, we should not set the accept header
|
||||
// here, according to the fetch spec
|
||||
|
|
|
@ -1350,11 +1350,6 @@ fn test_fetch_with_devtools() {
|
|||
//Creating default headers for request
|
||||
let mut headers = HeaderMap::new();
|
||||
|
||||
headers.insert(
|
||||
header::ACCEPT_ENCODING,
|
||||
HeaderValue::from_static("gzip, deflate, br"),
|
||||
);
|
||||
|
||||
headers.insert(header::ACCEPT, HeaderValue::from_static("*/*"));
|
||||
|
||||
headers.insert(
|
||||
|
@ -1364,6 +1359,20 @@ fn test_fetch_with_devtools() {
|
|||
|
||||
headers.typed_insert::<UserAgent>(DEFAULT_USER_AGENT.parse().unwrap());
|
||||
|
||||
let host = if url.port().is_none() {
|
||||
url.host_str().unwrap().to_string()
|
||||
} else {
|
||||
format!("{}:{}", url.host_str().unwrap(), url.port().unwrap())
|
||||
};
|
||||
headers.typed_insert(headers::Host::from(
|
||||
host.parse::<http::uri::Authority>().unwrap(),
|
||||
));
|
||||
|
||||
headers.insert(
|
||||
header::ACCEPT_ENCODING,
|
||||
HeaderValue::from_static("gzip, deflate, br"),
|
||||
);
|
||||
|
||||
let httprequest = DevtoolsHttpRequest {
|
||||
url: url,
|
||||
method: Method::GET,
|
||||
|
|
|
@ -136,9 +136,7 @@ fn test_check_default_headers_loaded_in_every_request() {
|
|||
|
||||
headers.insert(
|
||||
header::ACCEPT,
|
||||
HeaderValue::from_static(
|
||||
"text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8",
|
||||
),
|
||||
HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
|
||||
);
|
||||
|
||||
headers.insert(
|
||||
|
@ -268,16 +266,11 @@ fn test_request_and_response_data_with_network_messages() {
|
|||
//Creating default headers for request
|
||||
let mut headers = HeaderMap::new();
|
||||
|
||||
headers.insert(
|
||||
header::ACCEPT_ENCODING,
|
||||
HeaderValue::from_static("gzip, deflate, br"),
|
||||
);
|
||||
headers.insert(header::HOST, HeaderValue::from_static("bar.foo"));
|
||||
|
||||
headers.insert(
|
||||
header::ACCEPT,
|
||||
HeaderValue::from_static(
|
||||
"text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8",
|
||||
),
|
||||
HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
|
||||
);
|
||||
|
||||
headers.insert(
|
||||
|
@ -287,6 +280,11 @@ fn test_request_and_response_data_with_network_messages() {
|
|||
|
||||
headers.typed_insert::<UserAgent>(crate::DEFAULT_USER_AGENT.parse().unwrap());
|
||||
|
||||
headers.insert(
|
||||
header::ACCEPT_ENCODING,
|
||||
HeaderValue::from_static("gzip, deflate, br"),
|
||||
);
|
||||
|
||||
let httprequest = DevtoolsHttpRequest {
|
||||
url: url,
|
||||
method: Method::GET,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue