Skip to content

Commit

Permalink
Fixes for HTTP 400 errors from nginx in response to Servo requests.
Browse files Browse the repository at this point in the history
- Implement conformant albeit non-normative (but as implemented in Firefox, Safari, and Chrome) https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2 by removing whitespace from `Accept` and `Accept-Language` HTTP headers.
- Provide a `Host` header.
  • Loading branch information
philip-lamb committed Apr 2, 2024
1 parent 2817404 commit 20807b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions components/net/http_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
);
}

Expand Down Expand Up @@ -1225,7 +1225,17 @@ 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
Expand Down
6 changes: 3 additions & 3 deletions components/shared/net/quality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ where
fmt::Display::fmt(&self.item, fmt)?;
match self.quality.0 {
1000 => Ok(()),
0 => fmt.write_str("; q=0"),
0 => fmt.write_str(";q=0"),
mut x => {
fmt.write_str("; q=0.")?;
fmt.write_str(";q=0.")?;
let mut digits = *b"000";
digits[2] = (x % 10) as u8 + b'0';
x /= 10;
Expand All @@ -81,7 +81,7 @@ pub fn quality_to_value(q: Vec<QualityItem<Mime>>) -> HeaderValue {
&q.iter()
.map(|q| q.to_string())
.collect::<Vec<String>>()
.join(", "),
.join(","),
)
.unwrap()
}

0 comments on commit 20807b4

Please sign in to comment.