mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
convert match to if let for location header check #7969
This commit is contained in:
parent
7b904ef6fb
commit
4b363d2a0e
1 changed files with 37 additions and 43 deletions
|
@ -635,51 +635,45 @@ pub fn load<A>(load_data: LoadData,
|
||||||
|
|
||||||
// --- Loop if there's a redirect
|
// --- Loop if there's a redirect
|
||||||
if response.status().class() == StatusClass::Redirection {
|
if response.status().class() == StatusClass::Redirection {
|
||||||
match response.headers().get::<Location>() {
|
if let Some(&Location(ref new_url)) = response.headers().get::<Location>() {
|
||||||
Some(&Location(ref new_url)) => {
|
// CORS (https://fetch.spec.whatwg.org/#http-fetch, status section, point 9, 10)
|
||||||
// CORS (https://fetch.spec.whatwg.org/#http-fetch, status section, point 9, 10)
|
if let Some(ref c) = load_data.cors {
|
||||||
match load_data.cors {
|
if c.preflight {
|
||||||
Some(ref c) => {
|
return Err(
|
||||||
if c.preflight {
|
LoadError::Cors(
|
||||||
return Err(
|
url,
|
||||||
LoadError::Cors(
|
"Preflight fetch inconsistent with main fetch".to_owned()));
|
||||||
url,
|
} else {
|
||||||
"Preflight fetch inconsistent with main fetch".to_owned()));
|
// XXXManishearth There are some CORS-related steps here,
|
||||||
} else {
|
// but they don't seem necessary until credentials are implemented
|
||||||
// XXXManishearth There are some CORS-related steps here,
|
|
||||||
// but they don't seem necessary until credentials are implemented
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_doc_url = match UrlParser::new().base_url(&doc_url).parse(&new_url) {
|
|
||||||
Ok(u) => u,
|
|
||||||
Err(e) => {
|
|
||||||
return Err(LoadError::InvalidRedirect(doc_url, e.to_string()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("redirecting to {}", new_doc_url);
|
|
||||||
url = replace_hosts(&new_doc_url);
|
|
||||||
doc_url = new_doc_url;
|
|
||||||
|
|
||||||
// According to https://tools.ietf.org/html/rfc7231#section-6.4.2,
|
|
||||||
// historically UAs have rewritten POST->GET on 301 and 302 responses.
|
|
||||||
if method == Method::Post &&
|
|
||||||
(response.status() == StatusCode::MovedPermanently ||
|
|
||||||
response.status() == StatusCode::Found) {
|
|
||||||
method = Method::Get;
|
|
||||||
}
|
|
||||||
|
|
||||||
if redirected_to.contains(&url) {
|
|
||||||
return Err(LoadError::InvalidRedirect(doc_url, "redirect loop".to_owned()));
|
|
||||||
}
|
|
||||||
|
|
||||||
redirected_to.insert(doc_url.clone());
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
None => ()
|
|
||||||
|
let new_doc_url = match UrlParser::new().base_url(&doc_url).parse(&new_url) {
|
||||||
|
Ok(u) => u,
|
||||||
|
Err(e) => {
|
||||||
|
return Err(LoadError::InvalidRedirect(doc_url, e.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
info!("redirecting to {}", new_doc_url);
|
||||||
|
url = replace_hosts(&new_doc_url);
|
||||||
|
doc_url = new_doc_url;
|
||||||
|
|
||||||
|
// According to https://tools.ietf.org/html/rfc7231#section-6.4.2,
|
||||||
|
// historically UAs have rewritten POST->GET on 301 and 302 responses.
|
||||||
|
if method == Method::Post &&
|
||||||
|
(response.status() == StatusCode::MovedPermanently ||
|
||||||
|
response.status() == StatusCode::Found) {
|
||||||
|
method = Method::Get;
|
||||||
|
}
|
||||||
|
|
||||||
|
if redirected_to.contains(&url) {
|
||||||
|
return Err(LoadError::InvalidRedirect(doc_url, "redirect loop".to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
redirected_to.insert(doc_url.clone());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue