Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the http_loader code. #14362

Merged
merged 14 commits into from Nov 26, 2016

Return an io::Result from StreamedResponse::from_http_response().

  • Loading branch information
Ms2ger committed Nov 24, 2016
commit 47fa025e894db4116878941819de9e306df87df1
@@ -29,7 +29,7 @@ use hyper::status::StatusCode;
use hyper_serde::Serde;
use log;
use msg::constellation_msg::PipelineId;
use net_traits::{CookieSource, FetchMetadata, Metadata, NetworkError, ReferrerPolicy};
use net_traits::{CookieSource, FetchMetadata, NetworkError, ReferrerPolicy};
use net_traits::hosts::replace_hosts;
use net_traits::request::{CacheMode, CredentialsMode, Destination, Origin};
use net_traits::request::{RedirectMode, Referrer, Request, RequestMode, ResponseTainting};
@@ -218,7 +218,6 @@ impl LoadError {
enum LoadErrorType {
Connection { reason: String },
ConnectionAborted { reason: String },
Decoding { reason: String },
Ssl { reason: String },
}

@@ -233,7 +232,6 @@ impl Error for LoadErrorType {
match *self {
LoadErrorType::Connection { ref reason } => reason,
LoadErrorType::ConnectionAborted { ref reason } => reason,
LoadErrorType::Decoding { ref reason } => reason,
LoadErrorType::Ssl { ref reason } => reason,
}
}
@@ -389,17 +387,10 @@ impl Read for StreamedResponse {
}

impl StreamedResponse {
pub fn from_http_response(response: WrappedHttpResponse, m: Metadata) -> Result<StreamedResponse, LoadError> {
fn from_http_response(response: WrappedHttpResponse) -> io::Result<StreamedResponse> {
let decoder = match response.content_encoding() {
Some(Encoding::Gzip) => {
let result = GzDecoder::new(response);
match result {
Ok(response_decoding) => Decoder::Gzip(response_decoding),
Err(err) => {
return Err(
LoadError::new(m.final_url, LoadErrorType::Decoding { reason: err.to_string() }))
}
}
Decoder::Gzip(try!(GzDecoder::new(response)))
}
Some(Encoding::Deflate) => {
Decoder::Deflate(DeflateDecoder::new(response))
@@ -1155,7 +1146,7 @@ fn http_network_fetch(request: Rc<Request>,
let meta_status = meta.status.clone();
let meta_headers = meta.headers.clone();
spawn_named(format!("fetch worker thread"), move || {
match StreamedResponse::from_http_response(res, meta) {
match StreamedResponse::from_http_response(res) {
Ok(mut res) => {
*res_body.lock().unwrap() = ResponseBody::Receiving(vec![]);

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.