mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -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