mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Redirect document loads manually
This commit is contained in:
parent
779edd7c4a
commit
541baafe1c
17 changed files with 376 additions and 52 deletions
|
@ -42,7 +42,7 @@ use ipc_channel::Error as IpcError;
|
|||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use request::{Request, RequestInit};
|
||||
use response::{HttpsState, Response};
|
||||
use response::{HttpsState, Response, ResponseInit};
|
||||
use servo_url::ServoUrl;
|
||||
use std::error::Error;
|
||||
use storage_thread::StorageThreadMsg;
|
||||
|
@ -369,6 +369,8 @@ pub struct WebSocketConnectData {
|
|||
#[derive(Deserialize, Serialize)]
|
||||
pub enum CoreResourceMsg {
|
||||
Fetch(RequestInit, IpcSender<FetchResponseMsg>),
|
||||
/// Initiate a fetch in response to processing a redirection
|
||||
FetchRedirect(RequestInit, ResponseInit, IpcSender<FetchResponseMsg>),
|
||||
/// Try to make a websocket connection to a URL.
|
||||
WebsocketConnect(WebSocketCommunicate, WebSocketConnectData),
|
||||
/// Store a cookie for a given originating URL
|
||||
|
@ -435,6 +437,9 @@ pub struct Metadata {
|
|||
|
||||
/// Referrer Url
|
||||
pub referrer: Option<ServoUrl>,
|
||||
|
||||
/// Referrer Policy of the Request used to obtain Response
|
||||
pub referrer_policy: Option<ReferrerPolicy>,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
|
@ -449,6 +454,7 @@ impl Metadata {
|
|||
status: Some((200, b"OK".to_vec())),
|
||||
https_state: HttpsState::None,
|
||||
referrer: None,
|
||||
referrer_policy: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ pub enum Origin {
|
|||
}
|
||||
|
||||
/// A [referer](https://fetch.spec.whatwg.org/#concept-request-referrer)
|
||||
#[derive(Clone, PartialEq, HeapSizeOf)]
|
||||
#[derive(Clone, PartialEq, Serialize, Deserialize, HeapSizeOf)]
|
||||
pub enum Referrer {
|
||||
NoReferrer,
|
||||
/// Default referrer if nothing is specified
|
||||
|
@ -158,6 +158,8 @@ pub struct RequestInit {
|
|||
pub pipeline_id: Option<PipelineId>,
|
||||
pub redirect_mode: RedirectMode,
|
||||
pub integrity_metadata: String,
|
||||
// to keep track of redirects
|
||||
pub url_list: Vec<ServoUrl>,
|
||||
}
|
||||
|
||||
impl Default for RequestInit {
|
||||
|
@ -182,6 +184,7 @@ impl Default for RequestInit {
|
|||
pipeline_id: None,
|
||||
redirect_mode: RedirectMode::Follow,
|
||||
integrity_metadata: "".to_owned(),
|
||||
url_list: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +293,7 @@ impl Request {
|
|||
}
|
||||
|
||||
pub fn from_init(init: RequestInit) -> Request {
|
||||
let mut req = Request::new(init.url,
|
||||
let mut req = Request::new(init.url.clone(),
|
||||
Some(Origin::Origin(init.origin.origin())),
|
||||
false,
|
||||
init.pipeline_id);
|
||||
|
@ -314,6 +317,12 @@ impl Request {
|
|||
req.referrer_policy = init.referrer_policy;
|
||||
req.pipeline_id = init.pipeline_id;
|
||||
req.redirect_mode = init.redirect_mode;
|
||||
let mut url_list = init.url_list;
|
||||
if url_list.is_empty() {
|
||||
url_list.push(init.url);
|
||||
}
|
||||
req.redirect_count = url_list.len() as u32 - 1;
|
||||
req.url_list = url_list;
|
||||
req.integrity_metadata = init.integrity_metadata;
|
||||
req
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! The [Response](https://fetch.spec.whatwg.org/#responses) object
|
||||
//! resulting from a [fetch operation](https://fetch.spec.whatwg.org/#concept-fetch)
|
||||
use {FetchMetadata, FilteredMetadata, Metadata, NetworkError};
|
||||
use {FetchMetadata, FilteredMetadata, Metadata, NetworkError, ReferrerPolicy};
|
||||
use hyper::header::{AccessControlExposeHeaders, ContentType, Headers};
|
||||
use hyper::status::StatusCode;
|
||||
use hyper_serde::Serde;
|
||||
|
@ -74,6 +74,16 @@ pub enum ResponseMsg {
|
|||
Errored,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, HeapSizeOf)]
|
||||
pub struct ResponseInit {
|
||||
pub url: ServoUrl,
|
||||
#[serde(deserialize_with = "::hyper_serde::deserialize",
|
||||
serialize_with = "::hyper_serde::serialize")]
|
||||
#[ignore_heap_size_of = "Defined in hyper"]
|
||||
pub headers: Headers,
|
||||
pub referrer: Option<ServoUrl>,
|
||||
}
|
||||
|
||||
/// A [Response](https://fetch.spec.whatwg.org/#concept-response) as defined by the Fetch spec
|
||||
#[derive(Debug, Clone, HeapSizeOf)]
|
||||
pub struct Response {
|
||||
|
@ -97,6 +107,7 @@ pub struct Response {
|
|||
pub internal_response: Option<Box<Response>>,
|
||||
/// whether or not to try to return the internal_response when asked for actual_response
|
||||
pub return_internal: bool,
|
||||
pub referrer_policy: Option<ReferrerPolicy>,
|
||||
}
|
||||
|
||||
impl Response {
|
||||
|
@ -113,11 +124,19 @@ impl Response {
|
|||
cache_state: CacheState::None,
|
||||
https_state: HttpsState::None,
|
||||
referrer: None,
|
||||
referrer_policy: None,
|
||||
internal_response: None,
|
||||
return_internal: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_init(init: ResponseInit) -> Response {
|
||||
let mut res = Response::new(init.url);
|
||||
res.headers = init.headers;
|
||||
res.referrer = init.referrer;
|
||||
res
|
||||
}
|
||||
|
||||
pub fn network_error(e: NetworkError) -> Response {
|
||||
Response {
|
||||
response_type: ResponseType::Error(e),
|
||||
|
@ -131,6 +150,7 @@ impl Response {
|
|||
cache_state: CacheState::None,
|
||||
https_state: HttpsState::None,
|
||||
referrer: None,
|
||||
referrer_policy: None,
|
||||
internal_response: None,
|
||||
return_internal: true,
|
||||
}
|
||||
|
@ -263,6 +283,7 @@ impl Response {
|
|||
metadata.status = response.raw_status.clone();
|
||||
metadata.https_state = response.https_state;
|
||||
metadata.referrer = response.referrer.clone();
|
||||
metadata.referrer_policy = response.referrer_policy.clone();
|
||||
metadata
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue