mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
http_loader: Don't tail-call for redirects
Serving suggestion: git show -w Fixes #1325. Some of the control-flow reorganization is for clarity rather than out of necessity.
This commit is contained in:
parent
b26fe9a430
commit
5763937ecd
1 changed files with 52 additions and 45 deletions
|
@ -21,7 +21,9 @@ pub fn factory() -> LoaderTask {
|
||||||
f
|
f
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(url: Url, start_chan: Chan<LoadResponse>) {
|
fn load(mut url: Url, start_chan: Chan<LoadResponse>) {
|
||||||
|
// Loop to handle redirects.
|
||||||
|
loop {
|
||||||
assert!("http" == url.scheme);
|
assert!("http" == url.scheme);
|
||||||
|
|
||||||
info!("requesting {:s}", url.to_str());
|
info!("requesting {:s}", url.to_str());
|
||||||
|
@ -45,9 +47,10 @@ fn load(url: Url, start_chan: Chan<LoadResponse>) {
|
||||||
// FIXME: detect redirect loops
|
// FIXME: detect redirect loops
|
||||||
if 3 == (response.status.code() / 100) {
|
if 3 == (response.status.code() / 100) {
|
||||||
match response.headers.location {
|
match response.headers.location {
|
||||||
Some(url) => {
|
Some(new_url) => {
|
||||||
info!("redirecting to {:s}", url.to_str());
|
info!("redirecting to {:s}", new_url.to_str());
|
||||||
return load(url, start_chan);
|
url = new_url;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
|
@ -64,12 +67,16 @@ fn load(url: Url, start_chan: Chan<LoadResponse>) {
|
||||||
match response.read(buf) {
|
match response.read(buf) {
|
||||||
Some(len) => {
|
Some(len) => {
|
||||||
unsafe { vec::raw::set_len(&mut buf, len) };
|
unsafe { vec::raw::set_len(&mut buf, len) };
|
||||||
|
progress_chan.send(Payload(buf));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
progress_chan.send(Done(Ok(())));
|
progress_chan.send(Done(Ok(())));
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
progress_chan.send(Payload(buf));
|
}
|
||||||
|
|
||||||
|
// We didn't get redirected.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue