mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #25294 - Darkspirit:h2, r=jdm
Let hyper automatically set the host header if needed Google's gws web server did not expect to receive an unneeded Host header via HTTP/2, therefore it responded with 400 Bad Request over a working HTTP/2 connection. https://tools.ietf.org/html/rfc7540#page-55 > Clients that generate HTTP/2 requests directly SHOULD use the ":authority" pseudo-header field instead of the Host header field. It's hyper's job to take care of this for the HTTP/1 case, therefore we can remove old code. When calling [Client::builder()](1974c875a1/components/net/connector.rs (L116-L119)
) we do not disable hyper's default [set_host](4b6099c7aa/src/client/mod.rs (L1019-L1024)
) config option, therefore hyper [automatically adds a Host header for non-HTTP/2 connections](4b6099c7aa/src/client/mod.rs (L289-L292)
) based on the [URI](3f663d7ab2/components/net/http_loader.rs (L418-L421)
). r? @jdm --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #25286.
This commit is contained in:
commit
79408fa36b
4 changed files with 7 additions and 40 deletions
|
@ -24,11 +24,8 @@ use headers::{
|
|||
};
|
||||
use headers::{AccessControlAllowOrigin, AccessControlMaxAge};
|
||||
use headers::{CacheControl, ContentEncoding, ContentLength};
|
||||
use headers::{
|
||||
Host, IfModifiedSince, LastModified, Origin as HyperOrigin, Pragma, Referer, UserAgent,
|
||||
};
|
||||
use headers::{IfModifiedSince, LastModified, Origin as HyperOrigin, Pragma, Referer, UserAgent};
|
||||
use http::header::{self, HeaderName, HeaderValue};
|
||||
use http::uri::Authority;
|
||||
use http::{HeaderMap, Request as HyperRequest};
|
||||
use hyper::{Body, Client, Method, Response as HyperResponse, StatusCode};
|
||||
use hyper_serde::Serde;
|
||||
|
@ -995,24 +992,7 @@ fn http_network_or_cache_fetch(
|
|||
|
||||
// Step 5.16
|
||||
let current_url = http_request.current_url();
|
||||
if let Ok(host) = format!(
|
||||
"{}{}",
|
||||
current_url.host_str().unwrap(),
|
||||
current_url
|
||||
.port()
|
||||
.map(|v| format!(":{}", v))
|
||||
.unwrap_or("".into())
|
||||
)
|
||||
.parse::<Authority>()
|
||||
.map(Host::from)
|
||||
{
|
||||
http_request.headers.typed_insert(host);
|
||||
} else {
|
||||
// This error should only happen in cases where hyper and rust-url disagree
|
||||
// about how to parse an authority.
|
||||
// https://github.com/servo/servo/issues/24175
|
||||
error!("Failed to parse {} as authority", current_url);
|
||||
}
|
||||
http_request.headers.remove(header::HOST);
|
||||
|
||||
// unlike http_loader, we should not set the accept header
|
||||
// here, according to the fetch spec
|
||||
|
@ -1434,7 +1414,7 @@ fn http_network_fetch(
|
|||
};
|
||||
|
||||
if log_enabled!(log::Level::Info) {
|
||||
info!("response for {}", url);
|
||||
info!("{:?} response for {}", res.version(), url);
|
||||
for header in res.headers().iter() {
|
||||
info!(" - {:?}", header);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue