Skip to content

Commit

Permalink
Request constructor and fetch() method, add RedirectResponse named co…
Browse files Browse the repository at this point in the history
…nstructor too
  • Loading branch information
annevk committed May 28, 2014
1 parent b40f990 commit 2e82a88
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 15 deletions.
108 changes: 98 additions & 10 deletions Overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<p><a class="logo" href="//www.whatwg.org/"><img alt="WHATWG" height="100" src="//resources.whatwg.org/logo-fetch.svg" width="100"></a>
<h1 id="cors">Fetch</h1>
<h2 class="no-num no-toc" id="living-standard-—-last-updated-27-may-2014">Living Standard — Last Updated 27 May 2014</h2>
<h2 class="no-num no-toc" id="living-standard-—-last-updated-28-may-2014">Living Standard — Last Updated 28 May 2014</h2>

<dl>
<dt>This Version:
Expand All @@ -33,7 +33,7 @@ <h2 class="no-num no-toc" id="living-standard-—-last-updated-27-may-2014">Livi
<p class="copyright"><a href="http://creativecommons.org/publicdomain/zero/1.0/" rel="license"><img alt="CC0" src="http://i.creativecommons.org/p/zero/1.0/80x15.png"></a>
To the extent possible under law, the editor has waived all copyright and
related or neighboring rights to this work. In addition, as of
27 May 2014, the editor has made this specification available
28 May 2014, the editor has made this specification available
under the
<a href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0" rel="license">Open Web Foundation Agreement Version 1.0</a>,
which is available at
Expand Down Expand Up @@ -1621,7 +1621,7 @@ <h2 id="fetch-api"><span class="secno">5 </span>Fetch API</h2>

<h3 id="request-class"><span class="secno">5.1 </span>Request class</h3>

<pre class="idl">[<span title="dom-Request">Constructor</span>(<a class="external" href="http://encoding.spec.whatwg.org/#scalarvaluestring">ScalarValueString</a> <var title="">url</var>, optional <a href="#requestinit">RequestInit</a> <var title="">init</var>),
<pre class="idl">[<a href="#dom-request" title="dom-Request">Constructor</a>(<a class="external" href="http://encoding.spec.whatwg.org/#scalarvaluestring">ScalarValueString</a> <var title="">url</var>, optional <a href="#requestinit">RequestInit</a> <var title="">init</var>),
Exposed=Window,Worker]
interface <dfn id="request">Request</dfn> {
readonly attribute ByteString <span title="dom-Request-method">method</span>;
Expand Down Expand Up @@ -1654,10 +1654,57 @@ <h3 id="request-class"><span class="secno">5.1 </span>Request class</h3>
enum <dfn id="requestmode">RequestMode</dfn> { "same-origin", "tainted cross-origin", "CORS", "CORS-with-forced-preflight" };
enum <dfn id="requestomitcredentialsmode">RequestOmitCredentialsMode</dfn> { "always", "CORS", "never" };</pre>

<p>A <a href="#concept-request" title="concept-request">request</a> is represented by zero or more
<code><a href="#request">Request</a></code> objects. A <code><a href="#request">Request</a></code> object always has an associated
<a href="#concept-request" title="concept-request">request</a>.

<p>The <dfn id="dom-request" title="dom-Request"><code>Request(<var>url</var>, <var>init</var></code></dfn>
constructor must run these steps:

<ol>
<li><p>Let <var title="">parsedURL</var> be the result of
<a class="external" href="http://url.spec.whatwg.org/#concept-url-parser" title="concept-url-parser">parsing</a> <var title="">url</var>
with <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#entry-settings-object">entry settings object</a>'s
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#api-base-url">API base URL</a>.

<li><p>If <var title="">parsedURL</var> is failure,
<a class="external" href="http://heycam.github.io/webidl/#dfn-throw">throw</a> a <code title="">TypeError</code>.

<li><p>If <var title="">init</var>'s <code title="">method</code> member does not match the
<a class="external" href="http://tools.ietf.org/html/rfc2616/#section-5.1.1">Method</a> token production,
<a class="external" href="http://heycam.github.io/webidl/#dfn-throw">throw</a> a <code title="">TypeError</code>.

<li><p>If <var title="">init</var>'s <code title="">method</code> member is a
<a href="#concept-forbidden-methods" title="concept-forbidden-methods">forbidden method</a>,
<a class="external" href="http://heycam.github.io/webidl/#dfn-throw">throw</a> a <code title="">TypeError</code>.

<li><p class="XXX">Add case correction as in XMLHttpRequest? Technically subsets HTTP.

<li><p class="XXX">Deal with headers.

<li><p class="XXX">Deal with body.

<li><p>Let <var title="">r</var> be a new <a href="#concept-request" title="concept-request">request</a>, whose
<a href="#concept-request-url" title="concept-request-url">url</a> is <var title="">parsedURL</var>,
<a href="#concept-request-method" title="concept-request-method">method</a> is <var title="">init</var>'s
<code title="">method</code> member,
<a href="#concept-request-author-headers" title="concept-request-author-headers">author headers</a> is
<span class="XXX">...</span>,
<a href="#concept-request-body" title="concept-request-body">body</a> is <span class="XXX">...</span>,
<a href="#concept-request-mode" title="concept-request-mode">mode</a> is <var title="">init</var>'s
<code title="">mode</code> member,
and
<span title="concept-request-omitCredentialsMode">mode</span> is <var title="">init</var>'s
<code title="">omitCredentialsMode</code> member.

<li><p>Return a new <code><a href="#request">Request</a></code> object associated with <var title="">r</var>.
</ol>


<h3 id="response-class"><span class="secno">5.2 </span>Response class</h3>

<pre class="idl">[<span tilte="dom-Response">Constructor</span>(<span class="XXX">...</span> <var title="">body</var>, optional <a href="#responseinit">ResponseInit</a> <var title="">init</var>),
NamedConstructor=RedirectResponse(<a class="external" href="http://encoding.spec.whatwg.org/#scalarvaluestring">ScalarValueString</a> <var title="">url</var>, optional unsigned short <var title="">status</var> = 302),
Exposed=Window,Worker]
interface <dfn id="response">Response</dfn> {
readonly attribute <span>ResponseType</span> <span title="dom-Response-type">type</span>;
Expand All @@ -1682,14 +1729,55 @@ <h3 id="response-class"><span class="secno">5.2 </span>Response class</h3>

<h3 id="fetch-method"><span class="secno">5.3 </span>Fetch method</h3>

<pre class="idl">[NoInterfaceObject,
Exposed=Window,Worker]
interface GlobalFetch {
Promise&lt;Response&gt; <span title="dom-global-fetch">fetch</span>(<a class="external" href="http://encoding.spec.whatwg.org/#scalarvaluestring">ScalarValueString</a> <var title="">url</var>, optional <a href="#requestinit">RequestInit</a> <var title="">requestInit</var>);
Promise&lt;Response&gt; <span title="dom-global-fetch">fetch</span>(<a href="#request">Request</a> <var title="">request</var>);
<pre class="idl">[NoInterfaceObject]
interface <dfn id="globalfetch">GlobalFetch</dfn> {
Promise&lt;<a href="#response">Response</a>&gt; <a href="#dom-global-fetch" title="dom-global-fetch">fetch</a>(<a class="external" href="http://encoding.spec.whatwg.org/#scalarvaluestring">ScalarValueString</a> <var title="">url</var>, optional <a href="#requestinit">RequestInit</a> <var title="">requestInit</var>);
Promise&lt;<a href="#response">Response</a>&gt; <a href="#dom-global-fetch" title="dom-global-fetch">fetch</a>(<a href="#request">Request</a> <var title="">request</var>);
};
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a> implements <span>GlobalFetch</span>;
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#workerglobalscope">WorkerGlobalScope</a> implements <span>GlobalFetch</span>;</pre>
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a> implements <a href="#globalfetch">GlobalFetch</a>;
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#workerglobalscope">WorkerGlobalScope</a> implements <a href="#globalfetch">GlobalFetch</a>;</pre>

<p>The
<dfn id="dom-global-fetch" title="dom-global-fetch"><code>fetch(<var>url</var>, <var>requestInit</var>)</code></dfn>
and <code class="no-backref" title="dom-global-fetch"><a href="#dom-global-fetch">fetch(<var title="">request</var>)</a></code>
methods, must run these steps:

<ol>
<li><p>Let <var title="">p</var> be a new <code title="">Promise</code>.

<li><p class="XXX">Let <var title="">r</var> be the associated
<a href="#concept-request" title="concept-request">request</a> after invoking the
<code title="dom-Request"><a href="#dom-request">Request()</a></code> constructor with the same arguments as passed to
this algorithm. If this throws an exception, reject <var title="">p</var> with it.

<li>
<p>Run these substeps asynchronously:

<ol>
<li>
<p><a href="#concept-fetch" title="concept-fetch">Fetch</a> <var title="">r</var>.

<p>To <a href="#process-response">process response</a> for <var title="">response</var>, run these
subsubsteps:

<ol>
<li><p>Let <var title="">r</var> be a new <code><a href="#response">Response</a></code> object associated with
<var title="">response</var>.

<li><p>If <var title="">response</var>'s <a href="#concept-response-type" title="concept-response-type">type</a>
is <i title="">error</i>, reject <var title="">p</var> with a <code title="">TypeError</code>.

<li><p>Resolve <var title="">p</var> with <var title="">r</var>.
</ol>

<p>To <a href="#process-response-body">process response body</a> for <var title="">response</var>,
<span class="XXX">...</span>.

<p>To <a href="#process-response-end-of-file">process response end-of-file</a> for <var title="">response</var>,
<span class="XXX">...</span>.
</ol>
<li><p>Return <var title="">p</var>.
</ol>



Expand Down
98 changes: 93 additions & 5 deletions Overview.src.html
Original file line number Diff line number Diff line change
Expand Up @@ -1617,10 +1617,57 @@ <h3>Request class</h3>
enum <dfn>RequestMode</dfn> { "same-origin", "tainted cross-origin", "CORS", "CORS-with-forced-preflight" };
enum <dfn>RequestOmitCredentialsMode</dfn> { "always", "CORS", "never" };</pre>

<p>A <span title=concept-request>request</span> is represented by zero or more
<code>Request</code> objects. A <code>Request</code> object always has an associated
<span title=concept-request>request</span>.

<p>The <dfn title=dom-Request><code>Request(<var>url</var>, <var>init</var></code></dfn>
constructor must run these steps:

<ol>
<li><p>Let <var title>parsedURL</var> be the result of
<span data-anolis-spec=url title=concept-url-parser>parsing</span> <var title>url</var>
with <span data-anolis-spec=html>entry settings object</span>'s
<span data-anolis-spec=html>API base URL</span>.

<li><p>If <var title>parsedURL</var> is failure,
<span data-anolis-spec=webidl>throw</span> a <code title>TypeError</code>.

<li><p>If <var title>init</var>'s <code title>method</code> member does not match the
<span data-anolis-spec=http>Method</span> token production,
<span data-anolis-spec=webidl>throw</span> a <code title>TypeError</code>.

<li><p>If <var title>init</var>'s <code title>method</code> member is a
<span title=concept-forbidden-methods>forbidden method</span>,
<span data-anolis-spec=webidl>throw</span> a <code title>TypeError</code>.

<li><p class=XXX>Add case correction as in XMLHttpRequest? Technically subsets HTTP.

<li><p class=XXX>Deal with headers.

<li><p class=XXX>Deal with body.

<li><p>Let <var title>r</var> be a new <span title=concept-request>request</span>, whose
<span title=concept-request-url>url</span> is <var title>parsedURL</var>,
<span title=concept-request-method>method</span> is <var title>init</var>'s
<code title>method</code> member,
<span title=concept-request-author-headers>author headers</span> is
<span class=XXX>...</span>,
<span title=concept-request-body>body</span> is <span class=XXX>...</span>,
<span title=concept-request-mode>mode</span> is <var title>init</var>'s
<code title>mode</code> member,
and
<span title=concept-request-omitCredentialsMode>mode</span> is <var title>init</var>'s
<code title>omitCredentialsMode</code> member.

<li><p>Return a new <code>Request</code> object associated with <var title>r</var>.
</ol>


<h3>Response class</h3>

<pre class=idl>[<span tilte=dom-Response>Constructor</span>(<span class=XXX>...</span> <var title>body</var>, optional <span>ResponseInit</span> <var title>init</var>),
NamedConstructor=RedirectResponse(<span data-anolis-spec=encoding>ScalarValueString</span> <var title>url</var>, optional unsigned short <var title>status</var> = 302),
Exposed=Window,Worker]
interface <dfn>Response</dfn> {
readonly attribute <span>ResponseType</span> <span title=dom-Response-type>type</span>;
Expand All @@ -1645,15 +1692,56 @@ <h3>Response class</h3>

<h3>Fetch method</h3>

<pre class=idl>[NoInterfaceObject,
Exposed=Window,Worker]
interface GlobalFetch {
Promise&lt;Response> <span title=dom-global-fetch>fetch</span>(<span data-anolis-spec=encoding>ScalarValueString</span> <var title>url</var>, optional <span>RequestInit</span> <var title>requestInit</var>);
Promise&lt;Response> <span title=dom-global-fetch>fetch</span>(<span>Request</span> <var title>request</var>);
<pre class=idl>[NoInterfaceObject]
interface <dfn>GlobalFetch</dfn> {
Promise&lt;<span>Response</span>> <span title=dom-global-fetch>fetch</span>(<span data-anolis-spec=encoding>ScalarValueString</span> <var title>url</var>, optional <span>RequestInit</span> <var title>requestInit</var>);
Promise&lt;<span>Response</span>> <span title=dom-global-fetch>fetch</span>(<span>Request</span> <var title>request</var>);
};
<span data-anolis-spec=html>Window</span> implements <span>GlobalFetch</span>;
<span data-anolis-spec=html>WorkerGlobalScope</span> implements <span>GlobalFetch</span>;</pre>

<p>The
<dfn title=dom-global-fetch><code>fetch(<var>url</var>, <var>requestInit</var>)</code></dfn>
and <code title=dom-global-fetch class=no-backref>fetch(<var title>request</var>)</code>
methods, must run these steps:

<ol>
<li><p>Let <var title>p</var> be a new <code title>Promise</code>.

<li><p class=XXX>Let <var title>r</var> be the associated
<span title=concept-request>request</span> after invoking the
<code title=dom-Request>Request()</code> constructor with the same arguments as passed to
this algorithm. If this throws an exception, reject <var title>p</var> with it.

<li>
<p>Run these substeps asynchronously:

<ol>
<li>
<p><span title=concept-fetch>Fetch</span> <var title>r</var>.

<p>To <span>process response</span> for <var title>response</var>, run these
subsubsteps:

<ol>
<li><p>Let <var title>r</var> be a new <code>Response</code> object associated with
<var title>response</var>.

<li><p>If <var title>response</var>'s <span title=concept-response-type>type</span>
is <i title>error</i>, reject <var title>p</var> with a <code title>TypeError</code>.

<li><p>Resolve <var title>p</var> with <var title>r</var>.
</ol>

<p>To <span>process response body</span> for <var title>response</var>,
<span class=XXX>...</span>.

<p>To <span>process response end-of-file</span> for <var title>response</var>,
<span class=XXX>...</span>.
</ol>
<li><p>Return <var title>p</var>.
</ol>



<!-- XMLHttpRequest API -->
Expand Down

0 comments on commit 2e82a88

Please sign in to comment.