mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Make http_loader more robust against hyperium parse errors
This commit is contained in:
parent
1aeb97b281
commit
aeac382058
1 changed files with 29 additions and 17 deletions
|
@ -881,9 +881,16 @@ fn http_network_or_cache_fetch(
|
||||||
// Step 5.9
|
// Step 5.9
|
||||||
match http_request.referrer {
|
match http_request.referrer {
|
||||||
Referrer::NoReferrer => (),
|
Referrer::NoReferrer => (),
|
||||||
Referrer::ReferrerUrl(ref http_request_referrer) => http_request
|
Referrer::ReferrerUrl(ref http_request_referrer) => {
|
||||||
.headers
|
if let Ok(referer) = http_request_referrer.to_string().parse::<Referer>() {
|
||||||
.typed_insert::<Referer>(http_request_referrer.to_string().parse().unwrap()),
|
http_request.headers.typed_insert(referer);
|
||||||
|
} else {
|
||||||
|
// This error should only happen in cases where hyper and rust-url disagree
|
||||||
|
// about how to parse a referer.
|
||||||
|
// https://github.com/servo/servo/issues/24175
|
||||||
|
error!("Failed to parse {} as referer", http_request_referrer);
|
||||||
|
}
|
||||||
|
},
|
||||||
Referrer::Client =>
|
Referrer::Client =>
|
||||||
// it should be impossible for referrer to be anything else during fetching
|
// it should be impossible for referrer to be anything else during fetching
|
||||||
// https://fetch.spec.whatwg.org/#concept-request-referrer
|
// https://fetch.spec.whatwg.org/#concept-request-referrer
|
||||||
|
@ -946,20 +953,25 @@ fn http_network_or_cache_fetch(
|
||||||
|
|
||||||
// Step 5.16
|
// Step 5.16
|
||||||
let current_url = http_request.current_url();
|
let current_url = http_request.current_url();
|
||||||
let host = Host::from(
|
if let Ok(host) = format!(
|
||||||
format!(
|
"{}{}",
|
||||||
"{}{}",
|
current_url.host_str().unwrap(),
|
||||||
current_url.host_str().unwrap(),
|
current_url
|
||||||
current_url
|
.port()
|
||||||
.port()
|
.map(|v| format!(":{}", v))
|
||||||
.map(|v| format!(":{}", v))
|
.unwrap_or("".into())
|
||||||
.unwrap_or("".into())
|
)
|
||||||
)
|
.parse::<Authority>()
|
||||||
.parse::<Authority>()
|
.map(Host::from)
|
||||||
.unwrap(),
|
{
|
||||||
);
|
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.typed_insert(host);
|
|
||||||
// unlike http_loader, we should not set the accept header
|
// unlike http_loader, we should not set the accept header
|
||||||
// here, according to the fetch spec
|
// here, according to the fetch spec
|
||||||
set_default_accept_encoding(&mut http_request.headers);
|
set_default_accept_encoding(&mut http_request.headers);
|
||||||
|
@ -1484,7 +1496,7 @@ fn cors_preflight_fetch(
|
||||||
headers.sort();
|
headers.sort();
|
||||||
let headers = headers
|
let headers = headers
|
||||||
.iter()
|
.iter()
|
||||||
.map(|name| HeaderName::from_str(name).unwrap())
|
.filter_map(|name| HeaderName::from_str(name).ok())
|
||||||
.collect::<Vec<HeaderName>>();
|
.collect::<Vec<HeaderName>>();
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue