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
|
||||
match http_request.referrer {
|
||||
Referrer::NoReferrer => (),
|
||||
Referrer::ReferrerUrl(ref http_request_referrer) => http_request
|
||||
.headers
|
||||
.typed_insert::<Referer>(http_request_referrer.to_string().parse().unwrap()),
|
||||
Referrer::ReferrerUrl(ref http_request_referrer) => {
|
||||
if let Ok(referer) = http_request_referrer.to_string().parse::<Referer>() {
|
||||
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 =>
|
||||
// it should be impossible for referrer to be anything else during fetching
|
||||
// https://fetch.spec.whatwg.org/#concept-request-referrer
|
||||
|
@ -946,20 +953,25 @@ fn http_network_or_cache_fetch(
|
|||
|
||||
// Step 5.16
|
||||
let current_url = http_request.current_url();
|
||||
let host = Host::from(
|
||||
format!(
|
||||
"{}{}",
|
||||
current_url.host_str().unwrap(),
|
||||
current_url
|
||||
.port()
|
||||
.map(|v| format!(":{}", v))
|
||||
.unwrap_or("".into())
|
||||
)
|
||||
.parse::<Authority>()
|
||||
.unwrap(),
|
||||
);
|
||||
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.typed_insert(host);
|
||||
// unlike http_loader, we should not set the accept header
|
||||
// here, according to the fetch spec
|
||||
set_default_accept_encoding(&mut http_request.headers);
|
||||
|
@ -1484,7 +1496,7 @@ fn cors_preflight_fetch(
|
|||
headers.sort();
|
||||
let headers = headers
|
||||
.iter()
|
||||
.map(|name| HeaderName::from_str(name).unwrap())
|
||||
.filter_map(|name| HeaderName::from_str(name).ok())
|
||||
.collect::<Vec<HeaderName>>();
|
||||
|
||||
// Step 4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue