@@ -1556,6 +1556,9 @@ these steps:
1556
1556
1557
1557
<h4 id=requests>Requests</h4>
1558
1558
1559
+ <p class=note> This section documents how requests work in detail. To get started, see
1560
+ [[#fetch-elsewhere-request]] .
1561
+
1559
1562
<p> The input to <a for=/>fetch</a> is a
1560
1563
<dfn export id=concept-request>request</dfn> .
1561
1564
@@ -1741,7 +1744,7 @@ and "<code>webidentity</code>" as fetches with those destinations skip service w
1741
1744
"<code> xslt</code> " as that too can cause script execution. It is not included in the list as it is
1742
1745
not always relevant and might require different behavior.
1743
1746
1744
- <div class=note>
1747
+ <div class=note id=destination-table >
1745
1748
<p> The following table illustrates the relationship between a <a for=/>request</a> 's
1746
1749
<a for=request>initiator</a> , <a for=request>destination</a> , CSP directives, and features. It is
1747
1750
not exhaustive with respect to features. Features need to have the relevant values defined in their
@@ -8638,6 +8641,78 @@ correctly. This section aims to give some advice.
8638
8641
<p class=XXX> This is a work in progress.
8639
8642
8640
8643
8644
+ <h3 id=fetch-elsewhere-request>Setting up a request</h3>
8645
+
8646
+ <p> The first step in <a for=/>fetching</a> is to create a <a for=/>request</a> , and populate its
8647
+ <a for=struct>items</a> .
8648
+
8649
+ <p> Start by setting the <a for=/>request</a> 's <a for=request>URL</a> and <a for=request>method</a> ,
8650
+ as defined by HTTP. If your `<code> POST</code> ` or `<code> PUT</code> ` <a for=/>request</a> needs a
8651
+ body, you set <a for=/>request</a> 's <a for=request>body</a> to a <a for=/>byte sequence</a> , or to
8652
+ a new <a for=/>body</a> whose <a for=body>stream</a> is a {{ReadableStream}} you created. [[HTTP]]
8653
+
8654
+ <p> Choose your <a for=/>request</a> 's <a for=request>destination</a> using the guidance in the
8655
+ <a href="#destination-table">destination table</a> . <a for=request>Destinations</a> affect
8656
+ <cite> Content Security Policy</cite> and have other implications such as the [:Sec-Fetch-Dest:]
8657
+ header, so they are much more than informative metadata. If a new feature requires a
8658
+ <a for=request>destination</a> that's not in the <a href="#destination-table">destination table</a> ,
8659
+ please
8660
+ <a href="https://github.com/whatwg/fetch/issues/new?title=What%20destination%20should%20my%20feature%20use">file an issue</a>
8661
+ to discuss. [[CSP]]
8662
+
8663
+ <p> Set your <a for=/>request</a> 's <a for=request>client</a> to the
8664
+ <a>environment settings object</a> you're operating in. Web-exposed APIs are generally defined with
8665
+ Web IDL, for which every object that implements an <a>interface</a> has a
8666
+ <a>relevant settings object</a> you can use. For example, a <a for=/>request</a> associated with an
8667
+ <a for=/>element</a> would set the <a for=/>request</a> 's <a for=request>client</a> to the element' s
8668
+ <a>node document</a> 's <a>relevant settings object</a> . All features that are directly web-exposed
8669
+ by JavaScript, HTML, CSS, or other {{Document}} subresources should have a
8670
+ <a for=request>client</a> .
8671
+
8672
+ <p> If your <a for=/>fetching</a> is not directly web-exposed, e.g., it is sent in the background
8673
+ without relying on a current {{Window}} or {{Worker}} , leave <a for=/>request</a> 's
8674
+ <a for=request>client</a> as null and set the <a for=/>request</a> 's <a for=request>origin</a> ,
8675
+ <a for=request>policy container</a> , <a for=request>service-workers mode</a> , and
8676
+ <a for=request>referrer</a> to appropriate values instead, e.g., by copying them from the
8677
+ <a>environment settings object</a> ahead of time. In these more advanced cases, make sure the
8678
+ details of how your fetch handles <cite> Content Security Policy</cite> and
8679
+ <a for=/>referrer policy</a> are fleshed out. Also make sure you handle concurrency, as callbacks
8680
+ (see [[#fetch-elsewhere-fetch]] ) would be posted on a <a>parallel queue</a> . [[REFERRER]] [[CSP]]
8681
+
8682
+ <p> Think through the way you intend to handle cross-origin resources. Some features may only work in
8683
+ the <a>same origin</a> , in which case set your <a for=/>request</a> 's <a for=request>mode</a> to
8684
+ "<code> same-origin</code> ". Otherwise, new web-exposed features should almost always set their
8685
+ <a for=request>mode</a> to "<code> cors</code> ". If your feature is not web-exposed, or you think
8686
+ there is another reason for it to fetch cross-origin resources without CORS, please
8687
+ <a href="https://github.com/whatwg/fetch/issues/new?title=Does%20my%20request%20require%20CORS">file an issue</a>
8688
+ to discuss.
8689
+
8690
+ <p> For cross-origin requests, also determines if <a for=/>credentials</a> are to be included with
8691
+ the requests, in which case set your <a for=/>request</a> 's <a for=request>credentials mode</a> to
8692
+ "<code> include</code> ".
8693
+
8694
+ <p> Figure out if your fetch needs to be reported to <cite> Resource Timing</cite> , and with which
8695
+ <a for=request>initiator type</a> . By passing an <a for=request>initiator type</a> to the
8696
+ <a for=/>request</a> , reporting to <cite> Resource Timing</cite> will be done automatically once the
8697
+ fetch is done and the <a for=/>response</a> is fully downloaded. [[RESOURCE-TIMING]]
8698
+
8699
+ <p> If your request requires additional HTTP headers, set its <a for=request>header list</a> to
8700
+ a <a for=/>header list</a> that contains those headers, e.g., « (`<code> My-Header-Name</code> `,
8701
+ `<code> My-Header-Value</code> `) ». Sending custom headers may have implications, such as requiring a
8702
+ <a>CORS-preflight fetch</a> , so handle with care.
8703
+
8704
+ <p> If you want to override the default caching mechanism, e.g., disable caching for this
8705
+ <a for=/>request</a> , set the request's <a for=request>cache mode</a> to a value other than
8706
+ "<code> default</code> ".
8707
+
8708
+ <p> Determine whether you want your request to support redirects. If you don't, set its
8709
+ <a for=request>redirect mode</a> to "<code> error</code> ".
8710
+
8711
+ <p> Browse through the rest of the parameters for <a for=/>request</a> to see if something else is
8712
+ relevant to you. The rest of the parameters are used less frequently, often for special purposes,
8713
+ and they are documented in detail in the [[#requests]] section of this standard.
8714
+
8715
+
8641
8716
<h3 id=fetch-elsewhere-fetch class=no-num>Invoking fetch</h3>
8642
8717
8643
8718
<p> Aside from a <a for=/>request</a> the <a for=/>fetch</a> operation takes several optional
0 commit comments