Implement the Request API for the Fetch API.

This commit adds new files related to implementing the [Request
API](https://fetch.spec.whatwg.org/#request-class). This commit also
changes the expected web platform tests results. It also modifies the
following files:

components/net_traits/request.rs
HeapSizeOf is implemented in net_traits/request so that dom::request can
be used as a wrapper around net_traits::request::Request.

components/script/dom/headers.rs
Several methods are added to Headers so that request can access and
modify some of the headers fields.
This commit is contained in:
Jeena Lee 2016-07-19 18:38:02 -07:00
parent b7facf41cb
commit fabe2b8f7e
13 changed files with 1070 additions and 359 deletions

View file

@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// https://fetch.spec.whatwg.org/#body
[NoInterfaceObject,
Exposed=(Window,Worker)]
interface Body {
readonly attribute boolean bodyUsed;
// Servo does not support Promise at this moment.
// [NewObject] Promise<ArrayBuffer> arrayBuffer();
// [NewObject] Promise<Blob> blob();
// [NewObject] Promise<FormData> formData();
// [NewObject] Promise<JSON> json();
// [NewObject] Promise<USVString> text();
};

View file

@ -0,0 +1,108 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// https://fetch.spec.whatwg.org/#request-class
typedef (Request or USVString) RequestInfo;
[Constructor(RequestInfo input, optional RequestInit init),
Exposed=(Window,Worker)]
interface Request {
readonly attribute ByteString method;
readonly attribute USVString url;
[SameObject] readonly attribute Headers headers;
readonly attribute RequestType type;
readonly attribute RequestDestination destination;
readonly attribute USVString referrer;
readonly attribute ReferrerPolicy referrerPolicy;
readonly attribute RequestMode mode;
readonly attribute RequestCredentials credentials;
readonly attribute RequestCache cache;
readonly attribute RequestRedirect redirect;
readonly attribute DOMString integrity;
[NewObject, Throws] Request clone();
};
Request implements Body;
dictionary RequestInit {
ByteString method;
HeadersInit headers;
BodyInit? body;
USVString referrer;
ReferrerPolicy referrerPolicy;
RequestMode mode;
RequestCredentials credentials;
RequestCache cache;
RequestRedirect redirect;
DOMString integrity;
any window; // can only be set to null
};
enum RequestType {
"",
"audio",
"font",
"image",
"script",
"style",
"track",
"video"
};
enum RequestDestination {
"",
"document",
"embed",
"font",
"image",
"manifest",
"media",
"object",
"report",
"script",
"serviceworker",
"sharedworker",
"style",
"worker",
"xslt"
};
enum RequestMode {
"navigate",
"same-origin",
"no-cors",
"cors"
};
enum RequestCredentials {
"omit",
"same-origin",
"include"
};
enum RequestCache {
"default",
"no-store",
"reload",
"no-cache",
"force-cache",
"only-if-cached"
};
enum RequestRedirect {
"follow",
"error",
"manual"
};
enum ReferrerPolicy {
"",
"no-referrer",
"no-referrer-when-downgrade",
"origin",
"origin-when-cross-origin",
"unsafe-url"
};