Initial fetch refactor

This commit is contained in:
Keith Yeung 2015-08-18 17:35:51 -04:00
parent 9523283c14
commit ecf02a3656
3 changed files with 104 additions and 77 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use fetch::cors_cache::{CORSCache, CacheRequestDetails};
use fetch::response::{Response, ResponseType};
use fetch::response::ResponseMethods;
use hyper::header::{Accept, IfMatch, IfRange, IfUnmodifiedSince, Location};
use hyper::header::{AcceptLanguage, ContentLanguage, HeaderView};
use hyper::header::{ContentType, Header, Headers, IfModifiedSince, IfNoneMatch};
@ -11,9 +11,11 @@ use hyper::header::{QualityItem, q, qitem};
use hyper::method::Method;
use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value};
use hyper::status::StatusCode;
use net_traits::{AsyncFetchListener, Response, ResponseType, Metadata};
use std::ascii::AsciiExt;
use std::str::FromStr;
use url::Url;
use util::task::spawn_named;
/// A [request context](https://fetch.spec.whatwg.org/#concept-request-context)
#[derive(Copy, Clone, PartialEq)]
@ -112,7 +114,7 @@ pub struct Request {
pub redirect_mode: RedirectMode,
pub redirect_count: usize,
pub response_tainting: ResponseTainting,
pub cache: Option<Box<CORSCache + 'static>>
pub cache: Option<Box<CORSCache + Send>>
}
impl Request {
@ -145,6 +147,15 @@ impl Request {
}
}
pub fn fetch_async(mut self,
cors_flag: bool,
listener: Box<AsyncFetchListener + Send>) {
spawn_named(format!("fetch for {:?}", self.url.serialize()), move || {
let res = self.fetch(cors_flag);
listener.response_available(res);
});
}
/// [Fetch](https://fetch.spec.whatwg.org#concept-fetch)
pub fn fetch(&mut self, cors_flag: bool) -> Response {
// Step 1