mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Use RequestInit instead of LoadData. Make code look like the spec.
This commit is contained in:
parent
5e49873af7
commit
8bcf54deb5
4 changed files with 94 additions and 69 deletions
|
@ -196,18 +196,22 @@ pub trait FetchResponseListener {
|
|||
|
||||
impl FetchTaskTarget for IpcSender<FetchResponseMsg> {
|
||||
fn process_request_body(&mut self, _: &request::Request) {
|
||||
println!("PRqB");
|
||||
let _ = self.send(FetchResponseMsg::ProcessRequestBody);
|
||||
}
|
||||
|
||||
fn process_request_eof(&mut self, _: &request::Request) {
|
||||
println!("PRqE");
|
||||
let _ = self.send(FetchResponseMsg::ProcessRequestEOF);
|
||||
}
|
||||
|
||||
fn process_response(&mut self, response: &response::Response) {
|
||||
println!("PR");
|
||||
let _ = self.send(FetchResponseMsg::ProcessResponse(response.metadata()));
|
||||
}
|
||||
|
||||
fn process_response_eof(&mut self, response: &response::Response) {
|
||||
println!("PRE");
|
||||
if response.is_network_error() {
|
||||
// todo: finer grained errors
|
||||
let _ = self.send(FetchResponseMsg::ProcessResponse(Err(NetworkError::Internal("Network error".into()))));
|
||||
|
@ -412,7 +416,7 @@ pub struct WebSocketConnectData {
|
|||
pub enum CoreResourceMsg {
|
||||
/// Request the data associated with a particular URL
|
||||
Load(LoadData, LoadConsumer, Option<IpcSender<ResourceId>>),
|
||||
Fetch(LoadData, IpcSender<FetchResponseMsg>),
|
||||
Fetch(request::RequestInit, IpcSender<FetchResponseMsg>),
|
||||
/// Try to make a websocket connection to a URL.
|
||||
WebsocketConnect(WebSocketCommunicate, WebSocketConnectData),
|
||||
/// Store a set of cookies for a given originating URL
|
||||
|
|
|
@ -25,7 +25,7 @@ pub enum Type {
|
|||
}
|
||||
|
||||
/// A request [destination](https://fetch.spec.whatwg.org/#concept-request-destination)
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum Destination {
|
||||
None, Document, Embed, Font, Image, Manifest,
|
||||
Media, Object, Report, Script, ServiceWorker,
|
||||
|
@ -49,7 +49,7 @@ pub enum Referer {
|
|||
}
|
||||
|
||||
/// A [request mode](https://fetch.spec.whatwg.org/#concept-request-mode)
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum RequestMode {
|
||||
Navigate,
|
||||
SameOrigin,
|
||||
|
@ -58,7 +58,7 @@ pub enum RequestMode {
|
|||
}
|
||||
|
||||
/// Request [credentials mode](https://fetch.spec.whatwg.org/#concept-request-credentials-mode)
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[derive(Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum CredentialsMode {
|
||||
Omit,
|
||||
CredentialsSameOrigin,
|
||||
|
@ -107,6 +107,26 @@ pub enum CORSSettings {
|
|||
UseCredentials
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct RequestInit {
|
||||
pub method: Method,
|
||||
pub url: Url,
|
||||
pub headers: Headers,
|
||||
pub unsafe_request: bool,
|
||||
pub same_origin_data: bool,
|
||||
pub body: Option<Vec<u8>>,
|
||||
// TODO: cleint object
|
||||
pub destination: Destination,
|
||||
pub synchronous: bool,
|
||||
pub mode: RequestMode,
|
||||
pub use_cors_preflight: bool,
|
||||
pub credentials_mode: CredentialsMode,
|
||||
pub use_url_credentials: bool,
|
||||
// this should actually be set by fetch, but fetch
|
||||
// doesn't have info about the client right now
|
||||
pub origin: Url,
|
||||
}
|
||||
|
||||
/// A [Request](https://fetch.spec.whatwg.org/#requests) as defined by the Fetch spec
|
||||
#[derive(Clone)]
|
||||
pub struct Request {
|
||||
|
@ -186,6 +206,23 @@ impl Request {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_init(init: RequestInit) -> Request {
|
||||
let mut req = Request::new(init.url, None, false);
|
||||
*req.method.borrow_mut() = init.method;
|
||||
*req.headers.borrow_mut() = init.headers;
|
||||
req.unsafe_request = init.unsafe_request;
|
||||
req.same_origin_data.set(init.same_origin_data);
|
||||
*req.body.borrow_mut() = init.body;
|
||||
req.destination = init.destination;
|
||||
req.synchronous = init.synchronous;
|
||||
req.mode = init.mode;
|
||||
req.use_cors_preflight = init.use_cors_preflight;
|
||||
req.credentials_mode = init.credentials_mode;
|
||||
req.use_url_credentials = init.use_url_credentials;
|
||||
*req.origin.borrow_mut() = Origin::Origin(init.origin.origin());
|
||||
req
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#create-a-potential-cors-request
|
||||
pub fn potential_cors_request(url: Url,
|
||||
cors_attribute_state: Option<CORSSettings>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue