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:
Philip Lamb 2024-04-12 09:51:23 +12:00 committed by GitHub
parent 62a25fdcc4
commit 10ec8565ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 24 deletions

View file

@ -1350,20 +1350,29 @@ 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(
header::ACCEPT_LANGUAGE,
HeaderValue::from_static("en-US, en; q=0.5"),
HeaderValue::from_static("en-US,en;q=0.5"),
);
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,