-
Notifications
You must be signed in to change notification settings - Fork 324
/
Overview.src.html
5621 lines (4432 loc) · 256 KB
/
Overview.src.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang=en-US>
<meta charset=utf-8>
<title>Fetch Standard</title>
<link rel=stylesheet href=https://resources.whatwg.org/standard.css>
<link rel=icon href=https://resources.whatwg.org/logo-fetch.svg>
<div class=head>
<p><a class=logo href=https://whatwg.org/><img alt=WHATWG src=https://resources.whatwg.org/logo-fetch.svg width=100 height=100></a>
<h1 id=cors>Fetch</h1>
<h2 class="no-num no-toc">Living Standard — Last Updated [DATE: 3 August 2002]</h2>
<dl>
<dt>Participate:
<dd><a href=https://github.com/whatwg/fetch>GitHub whatwg/fetch</a>
(<a href=https://github.com/whatwg/fetch/issues/new>file an issue</a>,
<a href=https://github.com/whatwg/fetch/issues>open issues</a>,
<a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WHATWG&component=Fetch&resolution=---">legacy open bugs</a>)
<dd><a href=https://wiki.whatwg.org/wiki/IRC>IRC: #whatwg on Freenode</a>
<dt>Commits:
<dd><a href=https://github.com/whatwg/fetch/commits>GitHub whatwg/fetch/commits</a>
<dd><a href=https://twitter.com/fetchstandard>@fetchstandard</a>
<dt>Translation <small>(non-normative)</small>:
<dd title=Japanese><a href=https://triple-underscore.github.io/Fetch-ja.html lang=ja hreflang=ja rel=alternative>日本語</a>
</dl>
<script src=https://resources.whatwg.org/file-issue.js async></script>
<script id=head src=https://resources.whatwg.org/dfn.js defer></script>
</div>
<h2 class="no-num no-toc short">Abstract</h2>
<p>The Fetch standard defines requests, responses, and the process that binds them:
fetching.
<h2 class="no-num no-toc">Table of Contents</h2>
<!-- toc -->
<h2 class="no-num short">Goals</h2>
<p>To unify fetching across the web platform this specification supplants a number of algorithms and
specifications:
<ul class="brief no-backref">
<li>HTML Standard's fetch and potentially CORS-enabled fetch algorithms
<span data-anolis-ref class=informative>HTML</span>
<li>CORS <span data-anolis-ref class=informative>CORS</span>
<li>HTTP `<code title=http-origin>Origin</code>` header semantics
<span data-anolis-ref class=informative>ORIGIN</span>
</ul>
<p>Unifying fetching provides consistent handling of:
<ul class=brief>
<li>URL schemes
<li>Redirects
<li>Cross-origin semantics
<li>CSP <span data-anolis-ref>CSP</span>
<li>Service workers <span data-anolis-ref>SW</span>
<li>Mixed Content <span data-anolis-ref>MIX</span>
<li>`<code title>Referer</code>` <span data-anolis-ref>REFERRER</span>
</ul>
<h2 class=short>Preface</h2>
<p>At a high level, fetching a resource is a fairly simple operation. A request goes in, a
response comes out. <!--You can't explain that! -->The details of that operation are
however quite involved and used to not be written down carefully and differ from one API
to the next.
<p>Numerous APIs provide the ability to fetch a resource, e.g. HTML's <code>img</code> and
<code>script</code> element, CSS' <code>cursor</code> and <code>list-style-image</code>,
the <code>navigator.sendBeacon()</code> and <code>self.importScripts()</code> JavaScript
APIs. The Fetch Standard provides a unified architecture for these features so they are
all consistent when it comes to various aspects of fetching, such as redirects and the
CORS protocol.
<p>The Fetch Standard also defines the <code title=dom-global-fetch>fetch()</code>
JavaScript API, which exposes most of the networking functionality at a fairly low level
of abstraction.
<h2 class="short">Conformance</h2>
<p>All diagrams, examples, and notes in this specification are
non-normative, as are all sections explicitly marked non-normative.
Everything else in this specification is normative.
<p>The key words "MUST", "MUST NOT", "REQUIRED", <!--"SHALL", "SHALL
NOT",--> "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
"OPTIONAL" in the normative parts of this specification are to be
interpreted as described in RFC2119. For readability, these words do
not appear in all uppercase letters in this specification.
<span data-anolis-ref>RFC2119</span>
<h2>Infrastructure</h2>
<p>This specification uses terminology from the ABNF, Encoding, HTML, IDL, Streams, and URL Standards.
<span data-anolis-ref>ABNF</span>
<span data-anolis-ref>ENCODING</span>
<span data-anolis-ref>HTML</span>
<span data-anolis-ref>WEBIDL</span>
<span data-anolis-ref>STREAMS</span>
<span data-anolis-ref>URL</span>
<p>A <span data-anolis-spec=encoding>byte</span> sequence with bytes in the range 0x00 to
0x7F, inclusive, is represented as a <span data-anolis-spec=encoding>utf-8</span>-encoded
<span data-anolis-spec=encoding>string</span> with code points in the range U+0000 to
U+007F, inclusive. To avoid confusion with an actual string, backticks are used.
<p class=example>"<code title>true</code>" is a
<span data-anolis-spec=encoding>string</span>, while `<code title>true</code>` is a
byte sequence.
<p>Comparing two byte sequences in a <dfn>byte-case-insensitive</dfn> manner means
comparing them exactly, byte for byte, except that the bytes in the range 0x41 to 0x5A,
inclusive, are considered to also match their corresponding byte in the range 0x61 to
0x7A, inclusive.
<p>A <dfn>case-insensitive byte sequence</dfn> is a byte sequence that when compared to
another byte sequence does so in a <span>byte-case-insensitive</span> manner.
<p class=example>The
<span title="case-insensitive byte sequence">case-insensitive byte sequences</span>
`<code title>Content-Type</code>` and `<code title>content-TYPE</code>` are equal.
<p>To <dfn>byte-lowercase</dfn> a byte sequence, increase each byte it contains, in the
range 0x41 to 0x5A, inclusive, by 0x20.
<p>To <dfn>byte-uppercase</dfn> a byte sequence, subtract each byte it contains, in the
range 0x61 to 0x7A, inclusive, by 0x20.
<hr>
<p id="fetch-url">A <dfn>response URL</dfn> is a
<span data-anolis-spec=url title=concept-url>URL</span> for which implementations need not store the
<span data-anolis-spec=url title=concept-url-fragment>fragment</span> as it is never exposed. When
<span data-anolis-spec=url title=concept-url-serializer>serialized</span>, the
<i title>exclude fragment flag</i> is set, meaning implementations can store the
<span data-anolis-spec=url title=concept-url-fragment>fragment</span> nonetheless.
<hr>
<p><dfn>Credentials</dfn> are HTTP cookies, TLS client certificates, and
<span title="authentication entry">authentication entries</span>.
<hr>
<p><span data-anolis-spec=html title=concept-task>Tasks</span> that are
<span data-anolis-spec=html title="queue a task">queued</span> by this standard are annotated as one
of:
<ul class=brief>
<li><dfn>process request body</dfn>
<li id=process-request-end-of-file><dfn>process request end-of-body</dfn>
<li><dfn>process response</dfn>
<li id=process-response-end-of-file><dfn>process response end-of-body</dfn>
<li><dfn>process response done</dfn>
</ul>
<p>To <dfn>queue a fetch task</dfn> on <span title=concept-request>request</span>
<var>request</var> to <var>run an operation</var>, run these steps:
<ol>
<li><p>If <var>request</var>'s <span title=concept-request-client>client</span> is
null, terminate these steps.
<li><p><span data-anolis-spec=html>Queue a task</span> to
<var>run an operation</var> on <var>request</var>'s
<span title=concept-request-client>client</span>'s
<span data-anolis-spec=html>responsible event loop</span> using the
<span data-anolis-spec=html>networking task source</span>.
</ol>
<p>To <dfn>queue a fetch-request-done task</dfn>, given a <var>request</var>,
<span>queue a fetch task</span> on <var>request</var> to <span>process request end-of-body</span>
for <var>request</var>.
<hr>
<p>To <dfn>read a <var>request</var></dfn>, if <var>request</var>'s
<span title=concept-request-body>body</span> is non-null, whenever
<var>request</var>'s <span title=concept-request-body>body</span> is read from (i.e.
is transmitted or read by script), increase <var>request</var>'s
<span title=concept-request-body>body</span>'s
<span title=concept-body-transmitted>transmitted bytes</span> with the amount of payload body
bytes transmitted and then <span>queue a fetch task</span> on <var>request</var> to
<span>process request body</span> for <var>request</var>.
<!-- XXX xref "read", "payload body" -->
<h3>HTTP</h3>
<p>While <span title=concept-fetch>fetching</span> encompasses more than just HTTP, it
borrows a number of concepts from HTTP and applies these to resources obtained via other
means (e.g., <code title>data</code> URLs).
<p>The <dfn>HTTP whitespace bytes</dfn> are 0x09, 0x0A, 0x0D, and 0x20.
<p>An <dfn title=concept-https-state-value>HTTPS state value</dfn> is "<code title>none</code>",
"<code title>deprecated</code>", or "<code title>modern</code>".
<p class="note no-backref">A <span title=concept-response>response</span> delivered over HTTPS will
typically have its <span title=concept-response-https-state>HTTPS state</span> set to
"<code title>modern</code>". A user agent can use "<code title>deprecated</code>" in a transition
period. E.g., while removing support for a hash function, weak cypher suites, certificates for an
"Internal Name", or certificates with an overly long validity period. How exactly a user agent can
use "<code title>deprecated</code>" is not defined by this specification. An
<span data-anolis-spec=html>environment settings object</span> typically derives its
<span data-anolis-spec=html>HTTPS state</span> from a <span title=concept-response>response</span>.
<h4>Methods</h4>
<p>A <dfn title=concept-method data-export>method</dfn> is a byte sequence that matches the
<span data-anolis-spec=http>method</span> token production.
<p id=simple-method>A <dfn data-export>CORS-safelisted method</dfn> is a
<span title=concept-method>method</span> that is `<code title>GET</code>`,
`<code title>HEAD</code>`, or `<code title>POST</code>`.
<p>A <dfn data-export>forbidden method</dfn> is a <span title=concept-method>method</span> that is a
<span>byte-case-insensitive</span> match for `<code title>CONNECT</code>`,
`<code title>TRACE</code>`, or `<code title>TRACK</code>`.
<span data-anolis-ref class=informative>HTTPVERBSEC</span>
<p>To <dfn title=concept-method-normalize data-export data-dfn-for=method>normalize</dfn> a
<span title=concept-method>method</span>, if it is a <span>byte-case-insensitive</span>
match for `<code title>DELETE</code>`, `<code title>GET</code>`,
`<code title>HEAD</code>`, `<code title>OPTIONS</code>`, `<code title>POST</code>`, or
`<code title>PUT</code>`, <span>byte-uppercase</span> it.
<p class="note no-backref"><span title=concept-method-normalize>Normalization</span> is
done for backwards compatibility and consistency across APIs as
<span title=concept-method>methods</span> are actually "case-sensitive".
<p class="example">Using `<code title>patch</code>` is highly likely to result in a
`<code title>405 Method Not Allowed</code>`. `<code title>PATCH</code>` is much more likely to
succeed.
<p class="note no-backref">There are no restrictions on <span title=concept-method>methods</span>.
`<code title>CHICKEN</code>` is perfectly acceptable (and not a misspelling of
`<code title>CHECKIN</code>`). Other than those that are
<span title=concept-method-normalize>normalized</span> there are no casing restrictions either.
`<code title>Egg</code>` or `<code title>eGg</code>` would be fine, though uppercase is encouraged
for consistency.
<h4 id=terminology-headers>Headers</h4>
<p>A <dfn title=concept-header-list dfn-export>header list</dfn> consists of zero or more
<span title=concept-header>headers</span>.
<p class="note no-backref">A <span title=concept-header-list>header list</span> is essentially a
specialized multimap. An ordered list of key-value pairs with potentially duplicate keys.
<p>To <dfn title=concept-header-list-append data-export data-dfn-for="header list">append</dfn> a
<span title=concept-header-name>name</span>/<span title=concept-header-value>value</span>
(<var>name</var>/<var>value</var>) pair to a
<span title=concept-header-list>header list</span> (<var>list</var>), append a new
<span title=concept-header>header</span> whose <span title=concept-header-name>name</span>
is <var>name</var>, <span title="byte-lowercase">byte-lowercased</span>, and
<span title=concept-header-value>value</span> is <var>value</var>, to
<var>list</var>.
<p>To <dfn title=concept-header-list-delete data-export data-dfn-for="header list">delete</dfn> a
<span title=concept-header-name>name</span> (<var>name</var>) from a
<span title=concept-header-list>header list</span> (<var>list</var>), remove all
<span title=concept-header>headers</span> whose
<span title=concept-header-name>name</span> is <var>name</var>,
<span title="byte-lowercase">byte-lowercased</span>, from <var>list</var>.
<p>To <dfn title=concept-header-list-set data-export data-dfn-for="header list">set</dfn> a
<span title=concept-header-name>name</span>/<span title=concept-header-value>value</span>
(<var>name</var>/<var>value</var>) pair in a
<span title=concept-header-list>header list</span> (<var>list</var>), run these
steps:
<ol>
<li><p><span>Byte-lowercase</span> <var>name</var>.
<li><p>If there are any <span title=concept-header>headers</span> in
<var>list</var> whose <span title=concept-header-name>name</span> is
<var>name</var>, set the <span title=concept-header-value>value</span> of the first
such <span title=concept-header>header</span> to <var>value</var> and remove the
others.
<li><p>Otherwise, append a new <span title=concept-header>header</span> whose
<span title=concept-header-name>name</span> is <var>name</var> and
<span title=concept-header-value>value</span> is <var>value</var>, to
<var>list</var>.
</ol>
<p>To <dfn title=concept-header-list-combine data-export data-dfn-for="header list">combine</dfn> a
<span title=concept-header-name>name</span>/<span title=concept-header-value>value</span>
(<var>name</var>/<var>value</var>) pair in a
<span title=concept-header-list>header list</span> (<var>list</var>), run these
steps:
<ol>
<li><p><span>Byte-lowercase</span> <var>name</var>.
<li><p>If there are any <span title=concept-header>headers</span> in <var>list</var> whose
<span title=concept-header-name>name</span> is <var>name</var>, set the
<span title=concept-header-value>value</span> of the first such
<span title=concept-header>header</span> to its <span title=concept-header-value>value</span>,
followed by `<code>,</code>`, followed by <var>value</var>.
<li><p>Otherwise, append a new <span title=concept-header>header</span> whose
<span title=concept-header-name>name</span> is <var>name</var> and
<span title=concept-header-value>value</span> is <var>value</var>, to
<var>list</var>.
</ol>
<p class="note no-backref"><span title=concept-header-list-combine>Combine</span> is used by
<code data-anolis-spec=xhr>XMLHttpRequest</code> and the
<span title=concept-websocket-establish>WebSocket protocol handshake</span>.
<p>To
<dfn title=concept-header-list-sort-and-combine data-export data-dfn-for="header list">sort and combine</dfn>
a <span title=concept-header-list>header list</span> (<var>list</var>), run these steps:
<ol>
<li><p>Let <var>headers</var> be an empty list of
<span title=concept-header-name>name</span>-<span title=concept-header-value>value</span> pairs
with the key being the <span title=concept-header-name>name</span> and value the
<span title=concept-header-value>value</span>.
<li><p>Let <var>names</var> be all the <span title=concept-header-name>names</span> of the
<span title=concept-header>headers</span> in <var>list</var>, with duplicates removed, and sorted
lexicographically.
<li>
<p>For each <var>name</var> in <var>names</var>, run these substeps:
<ol>
<li><p>Let <var>value</var> be the
<span title=concept-header-value-combined>combined value</span> given <var>name</var> and
<var>list</var>.
<li><p>Append <var>name</var>-<var>value</var> to <var>headers</var>.
</ol>
<li><p>Return <var>headers</var>.
</ol>
<hr>
<p>A <dfn title=concept-header data-export>header</dfn> consists of a
<dfn title=concept-header-name data-export data-dfn-for=header>name</dfn> and
<dfn title=concept-header-value data-export data-dfn-for=header>value</dfn>.
A <span title=concept-header-name>name</span> is a
<span>case-insensitive byte sequence</span> that matches the
<span data-anolis-spec=http>field-name</span> token production. A
<span title=concept-header-value>value</span> is a byte sequence that matches the
<span data-anolis-spec=http>field-content</span> token production.
<p class="note no-backref"><span data-anolis-spec=http>field-value</span> allows 0x0A and
0x0D bytes which can lead to reparsing issues.
<p>To <dfn title=concept-header-value-normalize data-export data-dfn-for=header>normalize</dfn> a
<span title=concept-header-value>value</span>, remove any leading and trailing
<span>HTTP whitespace bytes</span> from it.
<p>A <dfn title=concept-header-value-combined data-export data-dfn-for=header>combined value</dfn>,
given a <span title=concept-header-name>name</span> (<var>name</var>) and
<span title=concept-header-list>header list</span> (<var>list</var>), is the
<span title=concept-header-value>values</span> of all <span title=concept-header>headers</span> in
<var>list</var> whose <span title=concept-header-name>name</span> is <var>name</var>, separated from
each other by `<code title>,</code>`, in order.
<hr>
<p id=simple-header>A <dfn data-export>CORS-safelisted request-header</dfn> is a
<span title=concept-header>header</span> whose <span title=concept-header-name>name</span> is one of
<ul class=brief>
<li>`<code title>Accept</code>`
<li>`<code title>Accept-Language</code>`
<li>`<code title>Content-Language</code>`
<li>`<code title>Content-Type</code>` and whose <span title=concept-header-value>value</span>,
<span title=concept-header-parse>once parsed</span>, has a MIME type (ignoring parameters)
that is `<code title>application/x-www-form-urlencoded</code>`,
`<code title>multipart/form-data</code>`, or `<code title>text/plain</code>`
</ul>
<!-- XXX * needs better xref
* ignoring parameters has been the standard for a long time now
* interesting test: "Content-Type: text/plain;" -->
<p>or whose <span title=concept-header-name>name</span> is one of
<ul class=brief>
<li>`<code title><a href=http://httpwg.org/http-extensions/client-hints.html#dpr>DPR</a></code>`
<li>`<code title><a href=http://httpwg.org/http-extensions/client-hints.html#downlink>Downlink</a></code>`
<li>`<code title><a href=http://httpwg.org/http-extensions/client-hints.html#save-data>Save-Data</a></code>`
<li>`<code title><a href=http://httpwg.org/http-extensions/client-hints.html#viewport-width>Viewport-Width</a></code>`
<li>`<code title><a href=http://httpwg.org/http-extensions/client-hints.html#width>Width</a></code>`
</ul>
<p>and whose <span title=concept-header-value>value</span>,
<span title=concept-header-parse>once parsed</span>, is not a failure.
<p>A <dfn data-export>CORS non-wildcard request-header name</dfn> is
`<code title>Authorization</code>`.
<p>A <dfn data-export>CORS-safelisted response-header name</dfn>, given a
<span title=concept-response-cors-exposed-header-name-list>CORS-exposed header-name list</span>
<var>list</var>, is a <span title=concept-header>header</span>
<span title=concept-header-name>name</span> that is one of
<ul class=brief>
<li>`<code title>Cache-Control</code>`
<li>`<code title>Content-Language</code>`
<li>`<code title>Content-Type</code>`
<li>`<code title>Expires</code>`
<li>`<code title>Last-Modified</code>`
<li>`<code title>Pragma</code>`
<li>Any <span title=concept-header-value>value</span> in <var>list</var> that is not a
<span>forbidden response-header name</span>.
</ul>
<p>A <dfn data-export>forbidden header name</dfn> is a <span title=concept-header>header</span>
<span title=concept-header-name>name</span> that is one of
<ul class=brief>
<li>`<code title>Accept-Charset</code>`
<li>`<code title>Accept-Encoding</code>`
<li>`<code title>Access-Control-Request-Headers</code>`
<li>`<code title>Access-Control-Request-Method</code>`
<li>`<code title>Connection</code>`
<li>`<code title>Content-Length</code>`
<li>`<code title>Cookie</code>`
<li>`<code title>Cookie2</code>`
<li>`<code title>Date</code>`
<li>`<code title>DNT</code>`
<li>`<code title>Expect</code>`
<li>`<code title>Host</code>`
<li>`<code title>Keep-Alive</code>`
<li>`<code title=http-origin>Origin</code>`
<li>`<code title>Referer</code>`
<li>`<code title>TE</code>`
<li>`<code title>Trailer</code>`
<li>`<code title>Transfer-Encoding</code>`
<li>`<code title>Upgrade</code>`
<li>`<code title>Via</code>`
</ul>
<p>or a <span title=concept-header>header</span> <span title=concept-header-name>name</span> that
starts with `<code title>Proxy-</code>` or `<code title>Sec-</code>` (including being just
`<code title>Proxy-</code>` or `<code title>Sec-</code>`).
<p class=note>These are forbidden so the user agent remains in full control over them.
<span title=concept-header-name>Names</span> starting with `<code title>Sec-</code>` are
reserved to allow new <span title=concept-header>headers</span> to be minted that are safe
from APIs using <span title=concept-fetch>fetch</span> that allow control over
<span title=concept-header>headers</span> by developers, such as
<code data-anolis-spec=xhr>XMLHttpRequest</code>.
<span data-anolis-ref class=informative>XHR</span>
<p>A <dfn data-export>forbidden response-header name</dfn> is a
<span title=concept-header>header</span> <span title=concept-header-name>name</span> that is one of:
<ul class=brief>
<li>`<code title>Set-Cookie</code>`
<li>`<code title>Set-Cookie2</code>`
</ul>
<hr>
<p>To <dfn title=concept-header-parse dfn-export>parse a header value</dfn> given a
<span title=concept-header-name>name</span> (<var>name</var>) and a
<span title=concept-header>header</span> or a <span title=concept-header-list>header list</span>
(<var>headers</var>), run these steps:
<ol>
<li><p>If <var>name</var> is not in <var>headers</var>, return null.
<li>
<p>If the ABNF for <var>name</var> allows a single
<span title=concept-header>header</span> and <var>headers</var> contains more than
one, return failure.
<p class="note no-backref">If different error handling is needed, extract the desired
<span title=concept-header>header</span> first.
<li><p>If parsing all the <span title=concept-header>headers</span>
<span title=concept-header-name>named</span> <var>name</var> in
<var>headers</var>, per the ABNF for <var>name</var>, failed, return failure.
<li><p>Return one or more <span title=concept-header-value>values</span> resulting from
parsing all the <span title=concept-header>headers</span>
<span title=concept-header-name>named</span> <var>name</var> in
<var>headers</var>, per the ABNF for <var>name</var>.
</ol>
<p>To
<dfn title=concept-header-extract-MIME-type data-export data-dfn-for="header list">extract a MIME type</dfn>
from a <span title=concept-header-list>header list</span> (<var>headers</var>), run these steps:
<ol>
<li><p>Let <var>MIMEType</var> be the result of
<span title=concept-header-parse>parsing</span> `<code title>Content-Type</code>` in
<var>headers</var>.
<li><p>If <var>MIMEType</var> is null or failure, return the empty byte sequence.
<li><p>Return <var>MIMEType</var>,
<span title="byte-lowercase">byte-lowercased</span>.
</ol>
<hr>
<p>A <dfn id=default-user-agent-value data-export>default `<code>User-Agent</code>` value</dfn> is a
user-agent-defined <span title=concept-header-value>value</span> for the
`<code title=http-user-agent>User-Agent</code>` <span title=concept-header>header</span>.
<h4>Statuses</h4>
<p>A <dfn id=concept-status data-export>status</dfn> is a code.
<p>A <dfn data-export>null body status</dfn> is a <span>status</span> that is <code>101</code>,
<code>204</code>, <code>205</code>, or <code>304</code>.
<p>An <dfn data-export>ok status</dfn> is any <span>status</span> in the range <code>200</code> to
<code>299</code>, inclusive.
<p>A <dfn data-export>redirect status</dfn> is a <span>status</span> that is <code>301</code>,
<code>302</code>, <code>303</code>, <code>307</code>, or <code>308</code>.
<h4>Bodies</h4>
<p>A <dfn title=concept-body data-export>body</dfn> consists of:
<ul>
<li>
<p>A <dfn title=concept-body-stream data-export data-dfn-for=body>stream</dfn> (a
<code title=concept-ReadableStream>ReadableStream</code> object).
<p class="XXX"><a href="https://github.com/whatwg/streams/issues/379">This might become a
<code>ReadableByteStream</code> object</a>. While the type might change, the behavior specified
will be equivalent since the hypothetical <code title>ReadableByteStream</code> object will have
the same members as the <code title=concept-ReadableStream>ReadableStream</code> object has today.
<li><p>A <dfn title=concept-body-transmitted data-export data-dfn-for=body>transmitted bytes</dfn>
(an integer), initially 0.
<li><p>A <dfn title=concept-body-total-bytes data-export data-dfn-for=body>total bytes</dfn> (an
integer), initially 0.
</ul>
<p>A <span title=concept-body>body</span> <var>body</var> is said to be
<dfn title=concept-body-done data-export data-dfn-for=body>done</dfn> if <var>body</var> is null or
<var>body</var>'s <span title=concept-body-stream>stream</span> is
<span title=concept-ReadableStream-closed>closed</span> or
<span title=concept-ReadableStream-errored>errored</span>.
<p>To <dfn title=concept-body-wait data-export data-dfn-for=body>wait</dfn> for a
<span title=concept-body>body</span> <var>body</var>, wait for <var>body</var> to be
<span title=concept-body-done>done</span>.
<p>To <dfn title=concept-body-clone data-export data-dfn-for=body>clone</dfn> a
<span title=concept-body>body</span> <var>body</var>, run these steps:
<ol>
<li><p>Let «<var>out1</var>, <var>out2</var>» be the result of
<span title=concept-tee-ReadableStream>teeing</span> <var>body</var>'s
<span title=concept-body-stream>stream</span>. Rethrow any exceptions.
<li><p>Set <var>body</var>'s <span title=concept-body-stream>stream</span> to <var>out1</var>.
<li><p>Return a <span title=concept-body>body</span> whose
<span title=concept-body-stream>stream</span> is <var>out2</var> and other members are copied from
<var>body</var>.
</ol>
<p>To <dfn data-export>handle content codings</dfn> given <var>codings</var> and
<var>bytes</var>, run these substeps:
<ol>
<li><p>If <var>codings</var> are not supported, return <var>bytes</var>.
<li><p>Return the result of decoding bytes with the given
<var>codings</var> as explained in HTTP. <span data-anolis-ref>HTTP</span>
</ol>
<!-- XXX no hook in HTTP -->
<h4>Requests</h4>
<p>The input to <span title=concept-fetch>fetch</span> is a
<dfn title=concept-request>request</dfn>.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-method>method</dfn> (a
<span title=concept-method>method</span>). Unless stated otherwise it is
`<code title>GET</code>`.
<p class="note no-backref">This can be updated during redirects to `<code title>GET</code>` as
described in <span title=concept-http-fetch>HTTP fetch</span>.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-url>url</dfn> (a
<span data-anolis-spec=url title=concept-url>URL</span>).
<p class="note no-backref">Implementations are encouraged to make this a pointer to the first
<span data-anolis-spec=url title=concept-url>URL</span> in
<span title=concept-request>request</span>'s <span title=concept-request-url-list>url list</span>.
It is provided as a distinct field solely for the convenience of other standards hooking into Fetch.
<p>A <span title=concept-request>request</span> has an associated
<dfn>local-URLs-only flag</dfn>. Unless stated otherwise it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn>sandboxed-storage-area-URLs flag</dfn>. Unless stated otherwise it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-header-list>header list</dfn> (a
<span title=concept-header-list>header list</span>). Unless stated otherwise it is empty.
<p>A <span title=concept-request>request</span> has an associated
<dfn>unsafe-request flag</dfn>. Unless stated otherwise it is unset.
<p class="note no-backref">The <span>unsafe-request flag</span> is set by APIs such as
<code title=dom-global-fetch>fetch()</code> and
<code data-anolis-spec=xhr>XMLHttpRequest</code> to ensure a
<span>CORS-preflight fetch</span> is done based on the supplied
<span title=concept-request-method>method</span> and
<span title=concept-request-header-list>header list</span>. It does not free an API from
outlawing <span title="forbidden method">forbidden methods</span> and
<span title="forbidden header name">forbidden header names</span>.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-body>body</dfn> (null or a
<span title=concept-body>body</span>). Unless stated otherwise it is null.
<p class="note no-backref">This can be updated during redirects to null as described in
<span title=concept-http-fetch>HTTP fetch</span>.
<hr>
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-client>client</dfn> (null or an
<span data-anolis-spec=html>environment settings object</span>).
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-window>window</dfn> ("<code>no-window</code>",
"<code>client</code>", or an
<span data-anolis-spec=html>environment settings object</span> whose
<span data-anolis-spec=html title=concept-settings-object-global>global object</span> is a
<code data-anolis-spec=html>Window</code> object). Unless stated otherwise it is
"<code>client</code>".
<p class="note no-backref">The "<code>client</code>" value is changed to "<code>no-window</code>" or
<span title=concept-request>request</span>'s <span title=concept-request-client>client</span> during
<span title=concept-fetch>fetching</span>. It provides a convenient way for standards to not have to
explicitly set <span title=concept-request>request</span>'s
<span title=concept-request-window>window</span>.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-target-browsing-context>target browsing context</dfn> (null or a
<span data-anolis-spec=html>browsing context</span>). Unless stated otherwise it is null.
<p>A <span title=concept-request>request</span> has an associated
<dfn>keep-alive flag</dfn>. Unless stated otherwise it is unset.
<p class="note no-backref">This is used by <code>navigator.sendBeacon</code> and the HTML
<code>img</code> element to outlive the
<span data-anolis-spec=html>environment settings object</span>.
<p>A <span title=concept-request>request</span> has an associated
<dfn>skip-service-worker flag</dfn>. Unless stated otherwise it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-initiator>initiator</dfn>, which is
the empty string,
"<code title>download</code>",
"<code title>imageset</code>",
"<code title>manifest</code>", or
"<code title>xslt</code>". Unless stated otherwise it is the empty string.
<p class="note no-backref">A <span title=concept-request>request</span>'s
<span title=concept-request-initiator>initiator</span> is not particularly granular for
the time being as other specifications do not require it to. It is primarily a
specification device to assist defining CSP and Mixed Content. It is not exposed to
JavaScript. <span data-anolis-ref>CSP</span> <span data-anolis-ref>MIX</span>
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-type>type</dfn>, which is
the empty string,
"<code title>audio</code>",
"<code title>font</code>",
"<code title>image</code>",
"<code title>script</code>",
"<code title>style</code>",
"<code title>track</code>", or
"<code title>video</code>". Unless stated otherwise it is the empty string.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-destination>destination</dfn>, which is
the empty string,
"<code title>document</code>",
"<code title>embed</code>",
"<code title>font</code>",
"<code title>image</code>",
"<code title>manifest</code>",
"<code title>media</code>",
"<code title>object</code>",
"<code title>report</code>",
"<code title>script</code>",
"<code title>serviceworker</code>",
"<code title>sharedworker</code>",
"<code title>style</code>",
"<code title>worker</code>", or
"<code title>xslt</code>". Unless stated otherwise it is the empty string.
<div class=note>
<p>The following table illustrates the relationship between a
<span title=concept-request>request</span>'s
<span title=concept-request-initiator>initiator</span>,
<span title=concept-request-type>type</span>,
<span title=concept-request-destination>destination</span>, CSP directives, and features.
<table>
<tr>
<th><span title=concept-request-initiator>Initiator</span>
<th><span title=concept-request-type>Type</span>
<th><span title=concept-request-destination>Destination</span>
<th>CSP directive
<th>Features
<tr>
<td rowspan=16>""
<td rowspan=6>""
<td>"<code title>report</code>"
<td rowspan=2>?
<td>CSP, NEL reports.
<tr>
<td>"<code title>document</code>"
<td>HTML's navigate algorithm.
<tr>
<td>"<code title>document</code>"
<td><code title>child-src</code>
<td>HTML's <code><iframe></code> and <code><frame></code>
<tr>
<td>""
<td><code title>connect-src</code>
<td><code>navigator.sendBeacon()</code>, <code>EventSource</code>,
HTML's <code>ping=""</code>, <code title=dom-global-fetch>fetch()</code>,
<code>XMLHttpRequest</code>, <code>WebSocket</code>, Cache API?
<tr>
<td>"<code title>object</code>"
<td><code title>object-src</code>
<td>HTML's <code><object></code>
<tr>
<td>"<code title>embed</code>"
<td><code title>object-src</code>
<td>HTML's <code><embed></code>
<tr>
<td>"<code title>audio</code>"
<td>"<code title>media</code>"
<td><code title>media-src</code>
<td>HTML's <code><audio></code>
<tr>
<td>"<code title>font</code>"
<td>"<code title>font</code>"
<td><code title>font-src</code>
<td>CSS' <code>@font-face</code>
<tr>
<td>"<code title>image</code>"
<td>"<code title>image</code>"
<td><code title>img-src</code>
<td>HTML's <code><img src></code>, <code title>/favicon.ico</code> resource,
SVG's <code><image></code>, CSS' <code>background-image</code>, CSS'
<code>cursor</code>, CSS' <code>list-style-image</code>, …
<tr>
<td rowspan=4>"<code title>script</code>"
<td>"<code title>script</code>"
<td><code title>script-src</code>
<td>HTML's <code><script></code>, <code>importScripts()</code>
<tr>
<td>"<code title>serviceworker</code>"
<td>?
<td><code title>navigator.serviceWorker.register()</code>
<tr>
<td>"<code title>sharedworker</code>"
<td><code title>child-src</code>
<td><code>SharedWorker</code>
<tr>
<td>"<code title>worker</code>"
<td><code title>child-src</code>
<td><code>Worker</code>
<tr>
<td>"<code title>style</code>"
<td>"<code title>style</code>"
<td><code title>style-src</code>
<td>HTML's <code><link rel=stylesheet></code>, CSS' <code>@import</code>
<tr>
<td>"<code title>track</code>"
<td>"<code title>media</code>"
<td><code title>media-src</code>
<td>HTML's <code><track></code>
<tr>
<td>"<code title>video</code>"
<td>"<code title>media</code>"
<td><code title>media-src</code>
<td>HTML's <code><video></code> element
<tr>
<td>"<code title>download</code>"
<td>""
<td>""
<td>?
<td>HTML's <code>download=""</code>, "Save Link As…" UI
<tr>
<td>"<code title>imageset</code>"
<td>"<code title>image</code>"
<td>"<code title>image</code>"
<td><code title>img-src</code>
<td>HTML's <code><img srcset></code> and <code><picture></code>
<tr>
<td>"<code title>manifest</code>"
<td rowspan=2>""
<td>"<code title>manifest</code>"
<td><code title>manifest-src</code>
<td>HTML's <code><link rel=manifest></code>
<tr>
<td>"<code title>xslt</code>"
<td>"<code title>xslt</code>"
<td><code title>script-src</code>
<td><code><?xml-stylesheet></code>
</table>
<p>CSP's <code>form-action</code> needs to be a hook directly in HTML's navigate or form
submission algorithm.
<p>CSP will also need to check
<span title=concept-request>request</span>'s
<span title=concept-request-client>client</span>'s
<span data-anolis-spec=html>browsing context</span>'s
<span data-anolis-spec=html title="ancestor browsing context">ancestor browsing contexts</span>
for various CSP directives.
</div>
<hr>
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-priority>priority</dfn> (null or a user-agent-defined object).
Unless otherwise stated it is null.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-origin>origin</dfn>, which is "<code>client</code>" or an
<span data-anolis-spec=html>origin</span>. Unless stated otherwise it is "<code>client</code>".
<p class="note no-backref">"<code>client</code>" is changed to an
<span data-anolis-spec=html>origin</span> during <span title=concept-fetch>fetching</span>. It
provides a convenient way for standards to not have to set
<span title=concept-request>request</span>'s <span title=concept-request-origin>origin</span>.
<span title=concept-request>Request</span>'s <span title=concept-request-origin>origin</span> can be
changed during redirects too.
<p>A <span title=concept-request>request</span> has an associated
<dfn>omit-<code>Origin</code>-header flag</dfn>. Unless stated otherwise it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn>same-origin data-URL flag</dfn>. Unless stated otherwise it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-referrer>referrer</dfn>, which is "<code>no-referrer</code>",
"<code>client</code>", or a <span data-anolis-spec=url title=concept-url>URL</span>.
Unless stated otherwise it is "<code>client</code>".
<p class="note no-backref">"<code>client</code>" is changed to "<code>no-referrer</code>" or a
<span data-anolis-spec=url title=concept-url>URL</span> during
<span title=concept-fetch>fetching</span>. It provides a convenient way for standards to not have to
set <span title=concept-request>request</span>'s
<span title=concept-request-referrer>referrer</span>.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-referrer-policy>referrer policy</dfn>, which is a
<span title=concept-referrer-policy>referrer policy</span>. Unless stated otherwise it is
the empty string.
<p class="note no-backref">This can be used to override a referrer policy associated with
an <span data-anolis-spec=html>environment settings object</span>.
<span data-anolis-ref>REFERRER</span>
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-client-hints-list>client hints list</dfn>, which is a
<span title=concept-client-hints-list>client-hints list</span>. Unless stated otherwise, it is
the empty list.
<p class="note no-backref">This will be used to override a client hints list associated with
an <span data-anolis-spec=html>environment settings object</span>.
<span data-anolis-ref>CLIENT-HINTS</span>
<p>A <span title=concept-request>request</span> has an associated
<dfn>synchronous flag</dfn>. Unless stated otherwise it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-mode>mode</dfn>, which is "<code title>same-origin</code>",
"<code title>cors</code>", "<code title>no-cors</code>", "<code title>navigate</code>", or
"<code title>websocket</code>". Unless stated otherwise, it is "<code title>no-cors</code>".
<p class="note no-backref">Even though the default <span title=concept-request>request</span>
<span title=concept-request-mode>mode</span> is "<code title>no-cors</code>", standards are highly
discouraged from using it for new features. It is rather unsafe. "<code title>navigate</code>" and
"<code title>websocket</code>" are special values for the HTML Standard.
<span data-anolis-ref>HTML</span>
<p>A <span title=concept-request>request</span> has an associated
<dfn>use-CORS-preflight flag</dfn>. Unless stated otherwise, it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-credentials-mode>credentials mode</dfn>, which is
"<code title>omit</code>", "<code title>same-origin</code>", or
"<code title>include</code>". Unless stated otherwise, it is "<code title>omit</code>".
<p class="note no-backref"><span title=concept-request>Request</span>'s
<span title=concept-request-credentials-mode>credentials mode</span> controls the flow of
<span>credentials</span> during a <span title=concept-fetch>fetch</span>. When
<span title=concept-request>request</span>'s <span title=concept-request-mode>mode</span> is
"<code title>navigate</code>", its
<span title=concept-request-credentials-mode>credentials mode</span> is assumed to be
"<code title>include</code>" and <span title=concept-fetch>fetch</span> does not currently account
for other values. If <cite>HTML</cite> changes here, this standard will need corresponding changes.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-use-url-credentials-flag>use-URL-credentials flag</dfn>.
Unless stated otherwise, it is unset.
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-cache-mode>cache mode</dfn>, which is "<code title>default</code>",
"<code title>no-store</code>", "<code title>reload</code>", "<code title>no-cache</code>",
"<code title>force-cache</code>", or "<code title>only-if-cached</code>". Unless stated otherwise,
it is "<code title>default</code>".
<div class="note no-backref">
<dl>
<dt>"<code title>default</code>"
<dd><span title=concept-fetch>Fetch</span> will inspect the HTTP cache on the way to the network.
If there is a fresh response it will be used. If there is a stale response a conditional request
will be created, and a normal request otherwise. It then updates the HTTP cache with the response.
<span data-anolis-ref>HTTP</span>
<dt>"<code title>no-store</code>"
<dd>Fetch behaves as if there is no HTTP cache at all.
<dt>"<code title>reload</code>"
<dd>Fetch behaves as if there is no HTTP cache on the way to the network. Ergo, it creates a
normal request and updates the HTTP cache with the response.
<dt>"<code title>no-cache</code>"
<dd>Fetch creates a conditional request if there is a response in the HTTP cache and a normal
request otherwise. It then updates the HTTP cache with the response.
<dt>"<code title>force-cache</code>"
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
staleness. If there was no response, it creates a normal request and updates the HTTP cache with
the response.
<dt>"<code title>only-if-cached</code>"
<dd>Fetch uses any response in the HTTP cache matching the request, not paying attention to
staleness. If there was no response, it returns a network error. (Can only be used when
<span title=concept-request>request</span>'s <span title=concept-request-mode>mode</span> is
"<code title>same-origin</code>". Any cached redirects will be followed assuming
<span title=concept-request>request</span>'s
<span title=concept-request-redirect-mode>redirect mode</span> is "<code>follow</code>" and the
redirects do not violate <span title=concept-request>request</span>'s
<span title=concept-request-mode>mode</span>.)
</dl>
<p>If <span title=concept-request-header-list>header list</span> contains a
<span title=concept-header>header</span> whose <span title=concept-header-name>name</span> is one
of
`<code title>If-Modified-Since</code>`,
`<code title>If-None-Match</code>`,
`<code title>If-Unmodified-Since</code>`,
`<code title>If-Match</code>`, and
`<code title>If-Range</code>`,
<span title=concept-fetch>fetch</span> will set
<span title=concept-request-cache-mode>cache mode</span> to "<code title>no-store</code>" if it is
"<code title>default</code>".
</div>
<p>A <span title=concept-request>request</span> has an associated
<dfn title=concept-request-redirect-mode>redirect mode</dfn>, which is
"<code title>follow</code>", "<code title>error</code>", or "<code title>manual</code>".
Unless stated otherwise, it is "<code title>follow</code>".