diff --git a/components/net/fetch/request.rs b/components/net/fetch/request.rs index 8daf650c338..3c3c10f45a5 100644 --- a/components/net/fetch/request.rs +++ b/components/net/fetch/request.rs @@ -15,8 +15,8 @@ use hyper::header::{QualityItem, q, qitem, Referer as RefererHeader, UserAgent}; use hyper::method::Method; use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value}; use hyper::status::StatusCode; -use net_traits::{AsyncFetchListener, CacheState, HttpsState, Response}; -use net_traits::{ResponseType, Metadata, TerminationReason}; +use net_traits::response::{CacheState, HttpsState, Response, ResponseType, TerminationReason}; +use net_traits::{AsyncFetchListener, Metadata}; use resource_task::CancellationListener; use std::ascii::AsciiExt; use std::cell::RefCell; diff --git a/components/net/fetch/response.rs b/components/net/fetch/response.rs index e0a97d24ca2..ff2e909368a 100644 --- a/components/net/fetch/response.rs +++ b/components/net/fetch/response.rs @@ -4,7 +4,7 @@ use hyper::header::Headers; use hyper::status::StatusCode; -use net_traits::{CacheState, HttpsState, Response, ResponseBody, ResponseType}; +use net_traits::response::{CacheState, HttpsState, Response, ResponseBody, ResponseType}; use std::ascii::AsciiExt; use std::cell::RefCell; use std::rc::Rc; diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index 44cc15145c3..30127935b9f 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -28,12 +28,9 @@ use hyper::header::{ContentType, Headers}; use hyper::http::RawStatus; use hyper::method::Method; use hyper::mime::{Attr, Mime}; -use hyper::status::StatusCode; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use msg::constellation_msg::{PipelineId}; use serde::{Deserializer, Serializer}; -use std::cell::RefCell; -use std::rc::Rc; use std::thread; use url::Url; use util::mem::HeapSizeOf; @@ -42,101 +39,9 @@ use websocket::header; pub mod hosts; pub mod image_cache_task; pub mod net_error_list; +pub mod response; pub mod storage_task; -/// [Response type](https://fetch.spec.whatwg.org/#concept-response-type) -#[derive(Clone, PartialEq, Copy)] -pub enum ResponseType { - Basic, - CORS, - Default, - Error, - Opaque, - OpaqueRedirect -} - -/// [Response termination reason](https://fetch.spec.whatwg.org/#concept-response-termination-reason) -#[derive(Clone, Copy)] -pub enum TerminationReason { - EndUserAbort, - Fatal, - Timeout -} - -/// The response body can still be pushed to after fetch -/// This provides a way to store unfinished response bodies -#[derive(Clone)] -pub enum ResponseBody { - Empty, // XXXManishearth is this necessary, or is Done(vec![]) enough? - Receiving(Vec), - Done(Vec), -} - -/// [Cache state](https://fetch.spec.whatwg.org/#concept-response-cache-state) -#[derive(Clone)] -pub enum CacheState { - None, - Local, - Validated, - Partial -} - -/// [Https state](https://fetch.spec.whatwg.org/#concept-response-https-state) -#[derive(Clone)] -pub enum HttpsState { - None, - Deprecated, - Modern -} - -pub enum ResponseMsg { - Chunk(Vec), - Finished, - Errored -} - -/// A [Response](https://fetch.spec.whatwg.org/#concept-response) as defined by the Fetch spec -#[derive(Clone)] -pub struct Response { - pub response_type: ResponseType, - pub termination_reason: Option, - pub url: Option, - pub url_list: Vec, - /// `None` can be considered a StatusCode of `0`. - pub status: Option, - pub headers: Headers, - pub body: ResponseBody, - pub cache_state: CacheState, - pub https_state: HttpsState, - /// [Internal response](https://fetch.spec.whatwg.org/#concept-internal-response), only used if the Response - /// is a filtered response - pub internal_response: Option>>, -} - -impl Response { - pub fn network_error() -> Response { - Response { - response_type: ResponseType::Error, - termination_reason: None, - url: None, - url_list: vec![], - status: None, - headers: Headers::new(), - body: ResponseBody::Empty, - cache_state: CacheState::None, - https_state: HttpsState::None, - internal_response: None - } - } - - pub fn is_network_error(&self) -> bool { - match self.response_type { - ResponseType::Error => true, - _ => false - } - } -} - /// Image handling. /// /// It may be surprising that this goes in the network crate as opposed to the graphics crate. @@ -197,7 +102,7 @@ impl LoadData { /// Interface for observing the final response for an asynchronous fetch operation. pub trait AsyncFetchListener { - fn response_available(&self, response: Response); + fn response_available(&self, response: response::Response); } /// A listener for asynchronous network events. Cancelling the underlying request is unsupported. diff --git a/components/net_traits/response.rs b/components/net_traits/response.rs new file mode 100644 index 00000000000..c9984afe450 --- /dev/null +++ b/components/net_traits/response.rs @@ -0,0 +1,104 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! The [Response](https://fetch.spec.whatwg.org/#responses) object +//! resulting from a [fetch operation](https://fetch.spec.whatwg.org/#concept-fetch) +use hyper::header::Headers; +use hyper::status::StatusCode; +use std::cell::RefCell; +use std::rc::Rc; +use url::Url; + +/// [Response type](https://fetch.spec.whatwg.org/#concept-response-type) +#[derive(Clone, PartialEq, Copy)] +pub enum ResponseType { + Basic, + CORS, + Default, + Error, + Opaque, + OpaqueRedirect +} + +/// [Response termination reason](https://fetch.spec.whatwg.org/#concept-response-termination-reason) +#[derive(Clone, Copy)] +pub enum TerminationReason { + EndUserAbort, + Fatal, + Timeout +} + +/// The response body can still be pushed to after fetch +/// This provides a way to store unfinished response bodies +#[derive(Clone)] +pub enum ResponseBody { + Empty, // XXXManishearth is this necessary, or is Done(vec![]) enough? + Receiving(Vec), + Done(Vec), +} + +/// [Cache state](https://fetch.spec.whatwg.org/#concept-response-cache-state) +#[derive(Clone)] +pub enum CacheState { + None, + Local, + Validated, + Partial +} + +/// [Https state](https://fetch.spec.whatwg.org/#concept-response-https-state) +#[derive(Clone)] +pub enum HttpsState { + None, + Deprecated, + Modern +} + +pub enum ResponseMsg { + Chunk(Vec), + Finished, + Errored +} + +/// A [Response](https://fetch.spec.whatwg.org/#concept-response) as defined by the Fetch spec +#[derive(Clone)] +pub struct Response { + pub response_type: ResponseType, + pub termination_reason: Option, + pub url: Option, + pub url_list: Vec, + /// `None` can be considered a StatusCode of `0`. + pub status: Option, + pub headers: Headers, + pub body: ResponseBody, + pub cache_state: CacheState, + pub https_state: HttpsState, + /// [Internal response](https://fetch.spec.whatwg.org/#concept-internal-response), only used if the Response + /// is a filtered response + pub internal_response: Option>>, +} + +impl Response { + pub fn network_error() -> Response { + Response { + response_type: ResponseType::Error, + termination_reason: None, + url: None, + url_list: vec![], + status: None, + headers: Headers::new(), + body: ResponseBody::Empty, + cache_state: CacheState::None, + https_state: HttpsState::None, + internal_response: None + } + } + + pub fn is_network_error(&self) -> bool { + match self.response_type { + ResponseType::Error => true, + _ => false + } + } +}