Skip to content
Permalink
Browse files

Introduce parser metadata for request

  • Loading branch information...
CYBAI committed May 9, 2019
1 parent ffdcd3a commit 261c8d9e0c4ec1ccd8d945b8ec133ac7b308978c
@@ -134,6 +134,14 @@ pub enum CorsSettings {
UseCredentials,
}

/// [Parser Metadata](https://fetch.spec.whatwg.org/#concept-request-parser-metadata)
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub enum ParserMetadata {
Default,
ParserInserted,
NotParserInserted,
}

#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct RequestBuilder {
#[serde(
@@ -169,6 +177,7 @@ pub struct RequestBuilder {
pub integrity_metadata: String,
// to keep track of redirects
pub url_list: Vec<ServoUrl>,
pub parser_metadata: ParserMetadata,
}

impl RequestBuilder {
@@ -194,6 +203,7 @@ impl RequestBuilder {
redirect_mode: RedirectMode::Follow,
integrity_metadata: "".to_owned(),
url_list: vec![],
parser_metadata: ParserMetadata::Default,
}
}

@@ -295,6 +305,11 @@ impl RequestBuilder {
self
}

pub fn parser_metadata(mut self, parser_metadata: ParserMetadata) -> RequestBuilder {
self.parser_metadata = parser_metadata;
self
}

pub fn build(self) -> Request {
let mut request = Request::new(
self.url.clone(),
@@ -323,6 +338,7 @@ impl RequestBuilder {
request.redirect_count = url_list.len() as u32 - 1;
request.url_list = url_list;
request.integrity_metadata = self.integrity_metadata;
request.parser_metadata = self.parser_metadata;
request
}
}
@@ -388,6 +404,8 @@ pub struct Request {
pub redirect_count: u32,
/// <https://fetch.spec.whatwg.org/#concept-request-response-tainting>
pub response_tainting: ResponseTainting,
/// <https://fetch.spec.whatwg.org/#concept-request-parser-metadata>
pub parser_metadata: ParserMetadata,
}

impl Request {
@@ -417,6 +435,7 @@ impl Request {
redirect_mode: RedirectMode::Follow,
integrity_metadata: String::new(),
url_list: vec![url],
parser_metadata: ParserMetadata::Default,
redirect_count: 0,
response_tainting: ResponseTainting::Basic,
}
@@ -37,7 +37,8 @@ use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsval::UndefinedValue;
use js::rust::HandleValue;
use msg::constellation_msg::{PipelineId, TopLevelBrowsingContextId};
use net_traits::request::{CredentialsMode, Destination, Referrer, RequestBuilder, RequestMode};
use net_traits::request::{CredentialsMode, Destination, ParserMetadata};
use net_traits::request::{Referrer, RequestBuilder, RequestMode};
use net_traits::IpcSend;
use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
use servo_rand::random;
@@ -312,6 +313,7 @@ impl DedicatedWorkerGlobalScope {
.destination(Destination::Worker)
.mode(RequestMode::SameOrigin)
.credentials_mode(CredentialsMode::CredentialsSameOrigin)
.parser_metadata(ParserMetadata::NotParserInserted)
.use_url_credentials(true)
.pipeline_id(pipeline_id)
.referrer(referrer)
@@ -31,7 +31,7 @@ use ipc_channel::router::ROUTER;
use js::jsapi::{JSAutoCompartment, JSContext, JS_AddInterruptCallback};
use js::jsval::UndefinedValue;
use msg::constellation_msg::PipelineId;
use net_traits::request::{CredentialsMode, Destination, Referrer, RequestBuilder};
use net_traits::request::{CredentialsMode, Destination, ParserMetadata, Referrer, RequestBuilder};
use net_traits::{CustomResponseMediator, IpcSend};
use script_traits::{
ScopeThings, ServiceWorkerMsg, TimerEvent, WorkerGlobalScopeInit, WorkerScriptLoadOrigin,
@@ -287,6 +287,7 @@ impl ServiceWorkerGlobalScope {
let request = RequestBuilder::new(script_url.clone())
.destination(Destination::ServiceWorker)
.credentials_mode(CredentialsMode::Include)
.parser_metadata(ParserMetadata::NotParserInserted)
.use_url_credentials(true)
.pipeline_id(pipeline_id)
.referrer(referrer)
@@ -42,7 +42,9 @@ use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind;
use js::rust::{HandleValue, ParentRuntime};
use msg::constellation_msg::PipelineId;
use net_traits::request::{CredentialsMode, Destination, RequestBuilder as NetRequestInit};
use net_traits::request::{
CredentialsMode, Destination, ParserMetadata, RequestBuilder as NetRequestInit,
};
use net_traits::IpcSend;
use script_traits::WorkerGlobalScopeInit;
use script_traits::{TimerEvent, TimerEventId};
@@ -216,6 +218,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
let request = NetRequestInit::new(url.clone())
.destination(Destination::Script)
.credentials_mode(CredentialsMode::Include)
.parser_metadata(ParserMetadata::NotParserInserted)
.use_url_credentials(true)
.origin(global_scope.origin().immutable().clone())
.pipeline_id(Some(self.upcast::<GlobalScope>().pipeline_id()))
@@ -124,6 +124,7 @@ fn request_init_from_request(request: NetTraitsRequest) -> RequestBuilder {
redirect_mode: request.redirect_mode,
integrity_metadata: "".to_owned(),
url_list: vec![],
parser_metadata: request.parser_metadata,
}
}

0 comments on commit 261c8d9

Please sign in to comment.
You can’t perform that action at this time.