Added devtools support to fetch for XHR + Manish's XHR ident fix

added unit test for request fetch with devtools

added devtools/fetch test
This commit is contained in:
ddh 2016-07-14 20:29:32 +01:00
parent 45209b7ffe
commit db808ca75d
9 changed files with 213 additions and 74 deletions

View file

@ -4,7 +4,7 @@
use hyper::header::Headers;
use hyper::method::Method;
use msg::constellation_msg::ReferrerPolicy;
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
use std::cell::{Cell, RefCell};
use std::mem::swap;
use url::{Origin as UrlOrigin, Url};
@ -130,6 +130,7 @@ pub struct RequestInit {
// XXXManishearth these should be part of the client object
pub referer_url: Option<Url>,
pub referrer_policy: Option<ReferrerPolicy>,
pub pipeline_id: Option<PipelineId>,
}
/// A [Request](https://fetch.spec.whatwg.org/#requests) as defined by the Fetch spec
@ -159,6 +160,7 @@ pub struct Request {
/// https://fetch.spec.whatwg.org/#concept-request-referrer
pub referer: RefCell<Referer>,
pub referrer_policy: Cell<Option<ReferrerPolicy>>,
pub pipeline_id: Cell<Option<PipelineId>>,
pub synchronous: bool,
pub mode: RequestMode,
pub use_cors_preflight: bool,
@ -178,7 +180,8 @@ pub struct Request {
impl Request {
pub fn new(url: Url,
origin: Option<Origin>,
is_service_worker_global_scope: bool) -> Request {
is_service_worker_global_scope: bool,
pipeline_id: Option<PipelineId>) -> Request {
Request {
method: RefCell::new(Method::Get),
local_urls_only: false,
@ -198,6 +201,7 @@ impl Request {
same_origin_data: Cell::new(false),
referer: RefCell::new(Referer::Client),
referrer_policy: Cell::new(None),
pipeline_id: Cell::new(pipeline_id),
synchronous: false,
mode: RequestMode::NoCORS,
use_cors_preflight: false,
@ -216,7 +220,7 @@ impl Request {
pub fn from_init(init: RequestInit) -> Request {
let mut req = Request::new(init.url,
Some(Origin::Origin(init.origin.origin())),
false);
false, init.pipeline_id);
*req.method.borrow_mut() = init.method;
*req.headers.borrow_mut() = init.headers;
req.unsafe_request = init.unsafe_request;
@ -234,6 +238,7 @@ impl Request {
Referer::NoReferer
};
req.referrer_policy.set(init.referrer_policy);
req.pipeline_id.set(init.pipeline_id);
req
}
@ -241,7 +246,8 @@ impl Request {
pub fn potential_cors_request(url: Url,
cors_attribute_state: Option<CORSSettings>,
is_service_worker_global_scope: bool,
same_origin_fallback: bool) -> Request {
same_origin_fallback: bool,
pipeline_id: Option<PipelineId>) -> Request {
Request {
method: RefCell::new(Method::Get),
local_urls_only: false,
@ -281,6 +287,7 @@ impl Request {
url_list: RefCell::new(vec![url]),
redirect_count: Cell::new(0),
response_tainting: Cell::new(ResponseTainting::Basic),
pipeline_id: Cell::new(pipeline_id),
done: Cell::new(false)
}
}