diff options
author | Keith Yeung <kungfukeith11@gmail.com> | 2015-08-18 17:35:51 -0400 |
---|---|---|
committer | Keith Yeung <kungfukeith11@gmail.com> | 2015-09-28 12:24:15 -0700 |
commit | ecf02a3656d60d4197e7cfc53beaedbc5e1019c0 (patch) | |
tree | 3ab1e19a7f47fd6ef362f48511cc0b39b51ab346 /components/net/fetch/request.rs | |
parent | 9523283c14f417014ca6d4fa8179c873bbb8f21f (diff) | |
download | servo-ecf02a3656d60d4197e7cfc53beaedbc5e1019c0.tar.gz servo-ecf02a3656d60d4197e7cfc53beaedbc5e1019c0.zip |
Initial fetch refactor
Diffstat (limited to 'components/net/fetch/request.rs')
-rw-r--r-- | components/net/fetch/request.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/components/net/fetch/request.rs b/components/net/fetch/request.rs index 1751fed49ba..d5b2439553a 100644 --- a/components/net/fetch/request.rs +++ b/components/net/fetch/request.rs @@ -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 |