mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
Use rust-http typed headers
This commit is contained in:
parent
48af4e53a9
commit
ec2111edbf
1 changed files with 13 additions and 17 deletions
|
@ -35,27 +35,23 @@ fn load(url: Url, start_chan: Chan<LoadResponse>) {
|
|||
}
|
||||
};
|
||||
|
||||
info!("got HTTP response %s, headers:", response.status.to_str())
|
||||
|
||||
let is_redirect = 3 == (response.status.code() / 100);
|
||||
let mut redirect: Option<Url> = None;
|
||||
// Dump headers, but only do the iteration if info!() is enabled.
|
||||
info!("got HTTP response %s, headers:", response.status.to_str());
|
||||
info!("%?",
|
||||
for header in response.headers.iter() {
|
||||
let name = header.header_name();
|
||||
let value = header.header_value();
|
||||
info!(" - %s: %s", name, value);
|
||||
if is_redirect && ("Location" == name) {
|
||||
redirect = Some(FromStr::from_str(value).expect("Failed to parse redirect URL"));
|
||||
}
|
||||
}
|
||||
info!(" - %s: %s", header.header_name(), header.header_value());
|
||||
});
|
||||
|
||||
// FIXME: detect redirect loops
|
||||
match redirect {
|
||||
if 3 == (response.status.code() / 100) {
|
||||
match response.headers.location {
|
||||
Some(url) => {
|
||||
info!("redirecting to %s", url.to_str());
|
||||
return load(url, start_chan);
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
let mut metadata = Metadata::default(url);
|
||||
// We will set other fields here.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue