mirror of
https://github.com/servo/servo.git
synced 2025-07-23 23:33:43 +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
|
@ -177,7 +177,7 @@ pub fn set_default_accept_language(headers: &mut HeaderMap) {
|
|||
// TODO(eijebong): Change this once typed headers are done
|
||||
headers.insert(
|
||||
header::ACCEPT_LANGUAGE,
|
||||
HeaderValue::from_static("en-US, en; q=0.5"),
|
||||
HeaderValue::from_static("en-US,en;q=0.5"),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue