auto merge of #1330 : kmcallister/servo/http_loader, r=pcwalton

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:
bors-servo 2013-12-04 09:43:24 -08:00
commit 7222048567

View file

@ -21,7 +21,9 @@ pub fn factory() -> LoaderTask {
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);
info!("requesting {:s}", url.to_str());
@ -45,9 +47,10 @@ fn load(url: Url, start_chan: Chan<LoadResponse>) {
// FIXME: detect redirect loops
if 3 == (response.status.code() / 100) {
match response.headers.location {
Some(url) => {
info!("redirecting to {:s}", url.to_str());
return load(url, start_chan);
Some(new_url) => {
info!("redirecting to {:s}", new_url.to_str());
url = new_url;
continue;
}
None => ()
}
@ -64,12 +67,16 @@ fn load(url: Url, start_chan: Chan<LoadResponse>) {
match response.read(buf) {
Some(len) => {
unsafe { vec::raw::set_len(&mut buf, len) };
progress_chan.send(Payload(buf));
}
None => {
progress_chan.send(Done(Ok(())));
return;
break;
}
}
progress_chan.send(Payload(buf));
}
// We didn't get redirected.
break;
}
}