mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Auto merge of #10629 - frewsxcv:flatten, r=Ms2ger
Flatten a couple `net` implementations. Working on some of the TLS related code in `net` and tried to clean up a couple implementations along the way. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10629) <!-- Reviewable:end -->
This commit is contained in:
commit
f39ec2b15e
2 changed files with 58 additions and 58 deletions
|
@ -72,54 +72,54 @@ pub fn factory(load_data: LoadData,
|
|||
cancel_listener: CancellationListener) {
|
||||
assert!(&*load_data.url.scheme == "file");
|
||||
spawn_named("file_loader".to_owned(), move || {
|
||||
let file_path: Result<PathBuf, ()> = load_data.url.to_file_path();
|
||||
match file_path {
|
||||
Ok(file_path) => {
|
||||
match File::open(&file_path) {
|
||||
Ok(ref mut reader) => {
|
||||
if cancel_listener.is_cancelled() {
|
||||
if let Ok(progress_chan) = get_progress_chan(load_data, file_path,
|
||||
senders, classifier, &[]) {
|
||||
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
|
||||
}
|
||||
return;
|
||||
}
|
||||
match read_block(reader) {
|
||||
Ok(ReadStatus::Partial(buf)) => {
|
||||
let progress_chan = get_progress_chan(load_data, file_path,
|
||||
senders, classifier, &buf).ok().unwrap();
|
||||
progress_chan.send(Payload(buf)).unwrap();
|
||||
let read_result = read_all(reader, &progress_chan, &cancel_listener);
|
||||
if let Ok(load_result) = read_result {
|
||||
match load_result {
|
||||
LoadResult::Cancelled => return,
|
||||
LoadResult::Finished => progress_chan.send(Done(Ok(()))).unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ReadStatus::EOF) => {
|
||||
if let Ok(chan) = get_progress_chan(load_data, file_path,
|
||||
senders, classifier, &[]) {
|
||||
let _ = chan.send(Done(Ok(())));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
send_error(load_data.url, e, senders);
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(_) => {
|
||||
// this should be one of the three errors listed in
|
||||
// http://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.open
|
||||
// but, we'll go for a "file not found!"
|
||||
let url = Url::parse("about:not-found").unwrap();
|
||||
let load_data_404 = LoadData::new(load_data.context, url, None);
|
||||
about_loader::factory(load_data_404, senders, classifier, cancel_listener)
|
||||
let file_path = match load_data.url.to_file_path() {
|
||||
Ok(file_path) => file_path,
|
||||
Err(_) => {
|
||||
send_error(load_data.url, "Could not parse path".to_owned(), senders);
|
||||
return;
|
||||
},
|
||||
};
|
||||
let mut file = File::open(&file_path);
|
||||
let reader = match file {
|
||||
Ok(ref mut reader) => reader,
|
||||
Err(_) => {
|
||||
// this should be one of the three errors listed in
|
||||
// http://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.open
|
||||
// but, we'll go for a "file not found!"
|
||||
let url = Url::parse("about:not-found").unwrap();
|
||||
let load_data_404 = LoadData::new(load_data.context, url, None);
|
||||
about_loader::factory(load_data_404, senders, classifier, cancel_listener);
|
||||
return;
|
||||
}
|
||||
};
|
||||
if cancel_listener.is_cancelled() {
|
||||
if let Ok(progress_chan) = get_progress_chan(load_data, file_path,
|
||||
senders, classifier, &[]) {
|
||||
let _ = progress_chan.send(Done(Err("load cancelled".to_owned())));
|
||||
}
|
||||
return;
|
||||
}
|
||||
match read_block(reader) {
|
||||
Ok(ReadStatus::Partial(buf)) => {
|
||||
let progress_chan = get_progress_chan(load_data, file_path,
|
||||
senders, classifier, &buf).ok().unwrap();
|
||||
progress_chan.send(Payload(buf)).unwrap();
|
||||
let read_result = read_all(reader, &progress_chan, &cancel_listener);
|
||||
if let Ok(load_result) = read_result {
|
||||
match load_result {
|
||||
LoadResult::Cancelled => return,
|
||||
LoadResult::Finished => progress_chan.send(Done(Ok(()))).unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
send_error(load_data.url, "Could not parse path".to_owned(), senders);
|
||||
Ok(ReadStatus::EOF) => {
|
||||
if let Ok(chan) = get_progress_chan(load_data, file_path,
|
||||
senders, classifier, &[]) {
|
||||
let _ = chan.send(Done(Ok(())));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
send_error(load_data.url, e, senders);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -198,19 +198,19 @@ pub trait HttpResponse: Read {
|
|||
"HTTP/1.1".to_owned()
|
||||
}
|
||||
fn content_encoding(&self) -> Option<Encoding> {
|
||||
self.headers().get::<ContentEncoding>().and_then(|h| {
|
||||
match *h {
|
||||
ContentEncoding(ref encodings) => {
|
||||
if encodings.contains(&Encoding::Gzip) {
|
||||
Some(Encoding::Gzip)
|
||||
} else if encodings.contains(&Encoding::Deflate) {
|
||||
Some(Encoding::Deflate)
|
||||
} else if encodings.contains(&Encoding::EncodingExt("br".to_owned())) {
|
||||
Some(Encoding::EncodingExt("br".to_owned()))
|
||||
} else { None }
|
||||
}
|
||||
}
|
||||
})
|
||||
let encodings = match self.headers().get::<ContentEncoding>() {
|
||||
Some(&ContentEncoding(ref encodings)) => encodings,
|
||||
None => return None,
|
||||
};
|
||||
if encodings.contains(&Encoding::Gzip) {
|
||||
Some(Encoding::Gzip)
|
||||
} else if encodings.contains(&Encoding::Deflate) {
|
||||
Some(Encoding::Deflate)
|
||||
} else if encodings.contains(&Encoding::EncodingExt("br".to_owned())) {
|
||||
Some(Encoding::EncodingExt("br".to_owned()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue