forked from whatwg/fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.bs
6219 lines (4816 loc) · 245 KB
/
fetch.bs
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
<pre class=metadata>
Title: Fetch Standard
Group: WHATWG
H1: Fetch
Shortname: fetch
Status: LS
No Editor: true
Abstract: The Fetch standard defines requests, responses, and the process that binds them: fetching.
Logo: https://resources.whatwg.org/logo-fetch.svg
Boilerplate: omit feedback-header, omit conformance, omit index, omit idl-index
Markup Shorthands: css off
!Participate: <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>)
!Participate: <a href=https://wiki.whatwg.org/wiki/IRC>IRC: #whatwg on Freenode</a>
!Commits: <a href=https://github.com/whatwg/fetch/commits>GitHub whatwg/fetch/commits</a>
!Commits: [SNAPSHOT-LINK]
!Commits: <a href=https://twitter.com/fetchstandard>@fetchstandard</a>
!Tests: <a href=https://github.com/w3c/web-platform-tests/tree/master/fetch>web-platform-tests fetch/</a> (<a href=https://github.com/w3c/web-platform-tests/labels/fetch>ongoing work</a>)
!Translation (non-normative): <span title=Japanese><a href=https://triple-underscore.github.io/Fetch-ja.html lang=ja hreflang=ja rel=alternate>日本語</a></span>
Translate IDs: typedefdef-bodyinit bodyinit,dictdef-requestinit requestinit,typedefdef-requestinfo requestinfo,enumdef-requestdestination requestdestination,enumdef-requestmode requestmode,enumdef-requestcredentials requestcredentials,enumdef-requestcache requestcache,enumdef-requestredirect requestredirect,dictdef-responseinit responseinit,enumdef-responsetype responsetype
</pre>
<script src=https://resources.whatwg.org/file-issue.js async></script>
<script src=https://resources.whatwg.org/commit-snapshot-shortcut-key.js async></script>
<script src=https://resources.whatwg.org/dfn.js defer></script>
<pre class=anchors>
url:https://tools.ietf.org/html/rfc7230#section-3.1.1;text:method;type:dfn;spec:http
url: https://tools.ietf.org/html/rfc7230#section-3.2;text:field-name;type:dfn;spec:http
url: https://tools.ietf.org/html/rfc7230#section-3.2;text:field-content; type:dfn;spec:http
url: https://tools.ietf.org/html/rfc7230#section-3.2;text:field-value; type:dfn;spec:http
url: https://tools.ietf.org/html/rfc7230#section-3.1.2;text:reason-phrase;type:dfn;spec:http
url: https://tools.ietf.org/html/rfc7234#section-1.2.1;text:delta-seconds;type:dfn;spec:http-caching
</pre>
<pre class=biblio>
{
"HTTP": {
"aliasOf": "RFC7230"
},
"HTTP-SEMANTICS": {
"aliasOf": "RFC7231"
},
"HTTP-COND": {
"aliasOf": "RFC7232"
},
"HTTP-CACHING": {
"aliasOf": "RFC7234"
},
"HTTP-RANGE": {
"aliasOf": "RFC7233"
},
"HTTP-AUTH": {
"aliasOf": "RFC7235"
},
"REFERRER": {
"aliasOf": "referrer-policy"
},
"SW": {
"aliasOf": "service-workers"
},
"UPGRADE": {
"aliasOf": "upgrade-insecure-requests"
},
"HSTS": {
"aliasOf": "RFC6797"
},
"WSP": {
"aliasOf": "RFC6455"
},
"CLIENT-HINTS": {
"authors": [
"Ilya Grigorik"
],
"href": "https://tools.ietf.org/html/draft-ietf-httpbis-client-hints",
"publisher": "IETF",
"title": "HTTP Client Hints"
},
"DATAURL": {
"authors": ["Simon Sapin"],
"href": "https://simonsapin.github.io/data-urls/",
"title": "The data URL scheme"
},
"HTTPVERBSEC1": {
"publisher": "US-CERT",
"href": "https://www.kb.cert.org/vuls/id/867593",
"title": "Multiple vendors' web servers enable HTTP TRACE method by default."
},
"HTTPVERBSEC2": {
"publisher": "US-CERT",
"href": "https://www.kb.cert.org/vuls/id/288308",
"title": "Microsoft Internet Information Server (IIS) vulnerable to cross-site scripting via HTTP TRACK method."
},
"HTTPVERBSEC3": {
"publisher": "US-CERT",
"href": "https://www.kb.cert.org/vuls/id/150227",
"title": "HTTP proxy default configurations allow arbitrary TCP connections."
},
"REPORTING": {
"authors": ["Ilya Grigorik", "Mike West"],
"href": "https://wicg.github.io/reporting/",
"title": "Reporting API"
},
"EXPECT-CT": {
"authors": [
"Emily Stark"
],
"href": "https://tools.ietf.org/html/draft-ietf-httpbis-expect-ct-02",
"publisher": "IETF",
"title": "Expect-CT Extension for HTTP"
},
"OCSP": {
"aliasOf": "RFC2560"
}
}
</pre>
<h2 id=goals 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
[[HTML]]
<li>CORS [[CORS]]
<li>HTTP `<a http-header><code>Origin</code></a>` header semantics
[[ORIGIN]]
</ul>
<p>Unifying fetching provides consistent handling of:
<ul class=brief>
<li>URL schemes
<li>Redirects
<li>Cross-origin semantics
<li>CSP [[!CSP]]
<li>Service workers [[!SW]]
<li>Mixed Content [[!MIX]]
<li>`<code>Referer</code>` [[!REFERRER]]
</ul>
<h2 id=preface 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 <a><code>fetch()</code></a>
JavaScript API, which exposes most of the networking functionality at a fairly low level
of abstraction.
<h2 id=infrastructure>Infrastructure</h2>
<p>This specification depends on the Infra Standard. [[!INFRA]]
<p>This specification uses terminology from the ABNF, Encoding, HTML, HTTP, IDL, Streams, and URL
Standards.
[[!ABNF]]
[[!ENCODING]]
[[!HTML]]
[[!HTTP]]
[[!WEBIDL]]
[[!STREAMS]]
[[!URL]]
<p><dfn>ABNF</dfn> means ABNF as modified by HTTP (in particular the addition <code>#</code>).
<hr>
<p><dfn id=credentials export>Credentials</dfn> are HTTP cookies, TLS client certificates, and <a
lt="authentication entry">authentication entries</a> (for HTTP authentication). [[!COOKIES]]
[[!TLS]] [[!HTTP-AUTH]]
<hr>
<p><a>Tasks</a> that are
<a lt="queue a task">queued</a> by this standard are annotated as one
of:
<ul class=brief>
<li><dfn export>process request body</dfn>
<li id=process-request-end-of-file><dfn export>process request end-of-body</dfn>
<li><dfn export>process response</dfn>
<li id=process-response-end-of-file><dfn export>process response end-of-body</dfn>
<li><dfn export>process response done</dfn>
</ul>
<p>To <dfn>queue a fetch task</dfn> on <a for=/>request</a>
<var>request</var> to <var>run an operation</var>, run these steps:
<ol>
<li><p>If <var>request</var>'s <a for=request>client</a> is
null, terminate these steps.
<li><p><a>Queue a task</a> to
<var>run an operation</var> on <var>request</var>'s
<a for=request>client</a>'s
<a>responsible event loop</a> using the
<a>networking task source</a>.
</ol>
<p>To <dfn>queue a fetch-request-done task</dfn>, given a <var>request</var>,
<a>queue a fetch task</a> on <var>request</var> to <a>process request end-of-body</a>
for <var>request</var>.
<h3 id=url>URL</h3>
<p>A <dfn export>local scheme</dfn> is a <a for=url>scheme</a> that is "<code>about</code>",
"<code>blob</code>", "<code>data</code>", or "<code>filesystem</code>".
<p>A <a for=/>URL</a> <dfn export>is local</dfn> if its <a for=url>scheme</a> is a
<a>local scheme</a>.
<p class=note>This definition is also used by <cite>Referrer Policy</cite>. [[REFERRER]]
<p>An <dfn export id=http-scheme>HTTP(S) scheme</dfn> is a <a for=url>scheme</a> that is
"<code>http</code>" or "<code>https</code>".
<p>A <dfn export>network scheme</dfn> is a <a for=url>scheme</a> that is "<code>ftp</code>" or an
<a>HTTP(S) scheme</a>.
<p>A <dfn export>fetch scheme</dfn> is a <a for=url>scheme</a> that is "<code>about</code>",
"<code>blob</code>", "<code>data</code>", "<code>file</code>", "<code>filesystem</code>", or a
<a>network scheme</a>.
<p class="note no-backref"><a>HTTP(S) scheme</a>, <a>network scheme</a>, and <a>fetch scheme</a> are
also used by <cite>HTML</cite>. [[HTML]]
<hr>
<p id=fetch-url>A <dfn>response URL</dfn> is a <a for=/>URL</a> for which implementations need not
store the <a for=url>fragment</a> as it is never exposed. When
<a lt="url serializer">serialized</a>, the <i>exclude fragment flag</i> is set, meaning
implementations can store the <a for=url>fragment</a> nonetheless.
<h3 id=http>HTTP</h3>
<p>While <a lt=fetch for=/>fetching</a> 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>data</code> URLs).
<p>The <dfn export>HTTP whitespace bytes</dfn> are 0x09, 0x0A, 0x0D, and 0x20.
<p>An <dfn export id=concept-https-state-value>HTTPS state value</dfn> is "<code>none</code>",
"<code>deprecated</code>", or "<code>modern</code>".
<p class="note no-backref">A <a for=/>response</a> delivered over HTTPS will
typically have its <a for=response>HTTPS state</a> set to
"<code>modern</code>". A user agent can use "<code>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>deprecated</code>" is not defined by this specification. An
<a>environment settings object</a> typically derives its
<a for="environment settings object">HTTPS state</a> from a <a for=/>response</a>.
<h4 id=methods>Methods</h4>
<p>A <dfn export id=concept-method>method</dfn> is a byte sequence that matches the
<a spec=http>method</a> token production.
<p id=simple-method>A <dfn export>CORS-safelisted method</dfn> is a
<a for=/>method</a> that is `<code>GET</code>`,
`<code>HEAD</code>`, or `<code>POST</code>`.
<p>A <dfn export>forbidden method</dfn> is a <a for=/>method</a> that is a
<a>byte-case-insensitive</a> match for `<code>CONNECT</code>`,
`<code>TRACE</code>`, or `<code>TRACK</code>`.
[[HTTPVERBSEC1]], [[HTTPVERBSEC2]], [[HTTPVERBSEC3]]
<p>To <dfn export for=method id=concept-method-normalize>normalize</dfn> a
<a for=/>method</a>, if it is a <a>byte-case-insensitive</a>
match for `<code>DELETE</code>`, `<code>GET</code>`,
`<code>HEAD</code>`, `<code>OPTIONS</code>`, `<code>POST</code>`, or
`<code>PUT</code>`, <a>byte-uppercase</a> it.
<p class="note no-backref"><a lt=normalize for=method>Normalization</a> is
done for backwards compatibility and consistency across APIs as
<a for=/>methods</a> are actually "case-sensitive".
<p id=example-normalization class=example>Using `<code>patch</code>` is highly likely to result in a
`<code>405 Method Not Allowed</code>`. `<code>PATCH</code>` is much more likely to
succeed.
<p class="note no-backref">There are no restrictions on <a for=/>methods</a>.
`<code>CHICKEN</code>` is perfectly acceptable (and not a misspelling of
`<code>CHECKIN</code>`). Other than those that are
<a lt=normalize for=method>normalized</a> there are no casing restrictions either.
`<code>Egg</code>` or `<code>eGg</code>` would be fine, though uppercase is encouraged
for consistency.
<h4 id=terminology-headers>Headers</h4>
<p>A <dfn export id=concept-header-list>header list</dfn> consists of zero or more
<a for=/>headers</a>.
<p class="note no-backref">A <a for=/>header list</a> is essentially a
specialized multimap. An ordered list of key-value pairs with potentially duplicate keys.
<p>A <a for=/>header list</a> (<var>list</var>)
<dfn export for="header list" lt="contains|does not contain">contains</dfn> a <a for=header>name</a>
(<var>name</var>) if <var>list</var> contains a <a for=/>header</a> whose <a for=header>name</a> is
a <a>byte-case-insensitive</a> match for <var>name</var>.
<p>To <dfn export for="header list" id=concept-header-list-append>append</dfn> a
<a for=header>name</a>/<a for=header>value</a> (<var>name</var>/<var>value</var>) pair to a
<a for=/>header list</a> (<var>list</var>), run these steps:
<ol>
<li>
<p>If <var>list</var> <a for="header list">contains</a> <var>name</var>, then set <var>name</var>
to the first such <a for=/>header</a>'s <a for=header>name</a>.
<p class="note no-backref">This reuses the casing of the <a for=header>name</a> of the
<a for=/>header</a> already in the <a for=/>header list</a>, if any. If there are multiple matched
<a for=/>headers</a> their <a for=header>names</a> will all be identical.
<!-- XXX Firefox and Safari adjust known header names too. -->
<li><p>Append a new <a for=/>header</a> whose <a for=header>name</a> is <var>name</var> and
<a for=header>value</a> is <var>value</var> to <var>list</var>.
</ol>
<p>To <dfn export for="header list" id=concept-header-list-delete>delete</dfn> a
<a for=header>name</a> (<var>name</var>) from a <a for=/>header list</a> (<var>list</var>), remove
all <a for=/>headers</a> whose <a for=header>name</a> is a <a>byte-case-insensitive</a> match for
<var>name</var> from <var>list</var>.
<p>To <dfn export for="header list" id=concept-header-list-set>set</dfn> a
<a for=header>name</a>/<a for=header>value</a> (<var>name</var>/<var>value</var>) pair in a
<a for=/>header list</a> (<var>list</var>), run these steps:
<ol>
<li><p>If <var>list</var> <a for="header list">contains</a> <var>name</var>, then set the
<a for=header>value</a> of the first such <a for=/>header</a> to <var>value</var> and remove the
others.
<li><p>Otherwise, append a new <a for=/>header</a> whose <a for=header>name</a> is <var>name</var>
and <a for=header>value</a> is <var>value</var> to <var>list</var>.
</ol>
<p>To <dfn export for="header list" id=concept-header-list-combine>combine</dfn> a
<a for=header>name</a>/<a for=header>value</a> (<var>name</var>/<var>value</var>) pair in a
<a for=/>header list</a> (<var>list</var>), run these steps:
<ol>
<li><p>If <var>list</var> <a for="header list">contains</a> <var>name</var>, then set the
<a for=header>value</a> of the first such <a for=/>header</a> to its <a for=header>value</a>,
followed by 0x2C 0x20, followed by <var>value</var>.
<li><p>Otherwise, append a new <a for=/>header</a> whose <a for=header>name</a> is <var>name</var>
and <a for=header>value</a> is <var>value</var> to <var>list</var>.
</ol>
<p class="note no-backref"><a for="header list">Combine</a> is used by {{XMLHttpRequest}} and the
<a lt="establish a WebSocket connection">WebSocket protocol handshake</a>.
<p>To
<dfn export for="header list" id=concept-header-list-sort-and-combine>sort and combine</dfn>
a <a for=/>header list</a> (<var>list</var>), run these steps:
<ol>
<li><p>Let <var>headers</var> be an empty list of
<a for=header>name</a>-<a for=header>value</a> pairs
with the key being the <a for=header>name</a> and value the
<a for=header>value</a>.
<li><p>Let <var>names</var> be all the <a lt=name for=header>names</a> of the
<a for=/>headers</a> in <var>list</var>, <a>byte-lowercased</a>, with duplicates removed, and
finally 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
<a for=header>combined value</a> 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 export id=concept-header>header</dfn> consists of a
<dfn export for=header id=concept-header-name>name</dfn> and
<dfn export for=header id=concept-header-value>value</dfn>.
<p>A <a for=header>name</a> is a <a>byte sequence</a> that matches the <a spec=http>field-name</a>
token production.
<p>A <a for=header>value</a> is a <a>byte sequence</a> that matches the following conditions:
<ul class=brief>
<li><p>Has no leading or trailing <a>HTTP whitespace bytes</a>.
<li><p>Contains no 0x00, 0x0A or 0x0D bytes.
</ul>
<p class=note>The definition of <a for=header>value</a> is not defined in terms of an HTTP token
production as
<a href=https://github.com/httpwg/http11bis/issues/19 title="fix field-value ABNF">it is broken</a>.
<p>To <dfn export for=header/value id=concept-header-value-normalize>normalize</dfn> a
<var>potentialValue</var>, remove any leading and trailing <a>HTTP whitespace bytes</a> from
<var>potentialValue</var>.
<p>A <dfn export for=header id=concept-header-value-combined>combined value</dfn>, given a
<a for=header>name</a> (<var>name</var>) and <a for=/>header list</a> (<var>list</var>), is the
<a lt=value for=header>values</a> of all <a for=/>headers</a> in <var>list</var> whose
<a for=header>name</a> is a <a>byte-case-insensitive</a> match for <var>name</var>, separated from
each other by 0x2C 0x20, in order.
<hr>
<p id=simple-header>A <dfn export>CORS-safelisted request-header</dfn> is a <a for=/>header</a>
whose <a for=header>name</a> is a <a>byte-case-insensitive</a> match for one of
<ul class=brief>
<li>`<code>Accept</code>`
<li>`<code>Accept-Language</code>`
<li>`<code>Content-Language</code>`
<li>`<code>Content-Type</code>` and whose <a for=header>value</a>,
<a lt="extract header values">once extracted</a>, has a MIME type (ignoring parameters)
that is `<code>application/x-www-form-urlencoded</code>`,
`<code>multipart/form-data</code>`, or `<code>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 <a for=header>name</a> is a <a>byte-case-insensitive</a> match for one of
<ul class=brief>
<li>`<code><a href=http://httpwg.org/http-extensions/client-hints.html#dpr>DPR</a></code>`
<li>`<code><a href=http://httpwg.org/http-extensions/client-hints.html#downlink>Downlink</a></code>`
<li>`<code><a href=http://httpwg.org/http-extensions/client-hints.html#save-data>Save-Data</a></code>`
<li>`<code><a href=http://httpwg.org/http-extensions/client-hints.html#viewport-width>Viewport-Width</a></code>`
<li>`<code><a href=http://httpwg.org/http-extensions/client-hints.html#width>Width</a></code>`
</ul>
<p>and whose <a for=header>value</a>, <a lt="extract header values">once extracted</a>, is not
failure.
<p class="note">There are limited exceptions to the `<code>Content-Type</code>` header safelist, as
documented in <a href=#cors-protocol-exceptions>CORS protocol exceptions</a>.
<p>A <dfn export>CORS non-wildcard request-header name</dfn> is a <a>byte-case-insensitive</a> match
for `<code>Authorization</code>`.
<p>A <dfn export>CORS-safelisted response-header name</dfn>, given a
<a for=response>CORS-exposed header-name list</a> <var>list</var>, is a <a for=/>header</a>
<a for=header>name</a> that is a <a>byte-case-insensitive</a> match for one of
<ul class=brief>
<li>`<code>Cache-Control</code>`
<li>`<code>Content-Language</code>`
<li>`<code>Content-Type</code>`
<li>`<code>Expires</code>`
<li>`<code>Last-Modified</code>`
<li>`<code>Pragma</code>`
<li>Any <a for=header>value</a> in <var>list</var> that is not a
<a>forbidden response-header name</a>.
</ul>
<p>A <dfn export>forbidden header name</dfn> is a <a for=/>header</a> <a for=header>name</a> that
is a <a>byte-case-insensitive</a> match for one of
<ul class=brief>
<li>`<code>Accept-Charset</code>`
<li>`<code>Accept-Encoding</code>`
<li>`<a http-header><code>Access-Control-Request-Headers</code></a>`
<li>`<a http-header><code>Access-Control-Request-Method</code></a>`
<li>`<code>Connection</code>`
<li>`<code>Content-Length</code>`
<li>`<code>Cookie</code>`
<li>`<code>Cookie2</code>`
<li>`<code>Date</code>`
<li>`<code>DNT</code>`
<li>`<code>Expect</code>`
<li>`<code>Host</code>`
<li>`<code>Keep-Alive</code>`
<li>`<a http-header><code>Origin</code></a>`
<li>`<code>Referer</code>`
<li>`<code>TE</code>`
<li>`<code>Trailer</code>`
<li>`<code>Transfer-Encoding</code>`
<li>`<code>Upgrade</code>`
<li>`<code>Via</code>`
</ul>
<p>or a <a for=/>header</a> <a for=header>name</a> that
starts with a <a>byte-case-insensitive</a> match for `<code>Proxy-</code>` or `<code>Sec-</code>`
(including being a <a>byte-case-insensitive</a> match for just `<code>Proxy-</code>` or
`<code>Sec-</code>`).
<p class=note>These are forbidden so the user agent remains in full control over them.
<a for=header>Names</a> starting with `<code>Sec-</code>` are
reserved to allow new <a for=/>headers</a> to be minted that are safe
from APIs using <a for=/>fetch</a> that allow control over
<a for=/>headers</a> by developers, such as
{{XMLHttpRequest}}.
[[XHR]]
<p>A <dfn export>forbidden response-header name</dfn> is a <a for=/>header</a>
<a for=header>name</a> that is a <a>byte-case-insensitive</a> match for one of:
<ul class=brief>
<li>`<code>Set-Cookie</code>`
<li>`<code>Set-Cookie2</code>`
</ul>
<hr>
<p>To <dfn export lt="extract header values|extracting header values">extract header values</dfn>
given a <a for=/>header</a> <var>header</var>, run these steps:
<ol>
<li><p>If parsing <var>header</var>'s <a for=header>value</a>, per the <a>ABNF</a> for
<var>header</var>'s <a for=header>name</a>, fails, then return failure.
<li><p>Return one or more <a for=header>values</a> resulting from parsing <var>header</var>'s
<a for=header>value</a>, per the <a>ABNF</a> for <var>header</var>'s <a for=header>name</a>.
</ol>
<p>To
<dfn export lt="extract header list values|extracting header list values">extract header list values</dfn>
given a <a for=header>name</a> (<var>name</var>) and a <a for=/>header list</a> (<var>list</var>),
run these steps:
<ol>
<li><p>If <var>list</var> <a for="header list">does not contain</a> <var>name</var>, then return
null.
<li>
<p>If the <a>ABNF</a> for <var>name</var> allows a single <a for=/>header</a> and <var>list</var>
<a for="header list">contains</a> more than one, then return failure.
<p class="note no-backref">If different error handling is needed, extract the desired
<a for=/>header</a> first.
<li><p>Let <var>values</var> be an empty <a for=/>list</a>.
<li>
<p>For each <a for=/>header</a> <var>header</var> <var>list</var>
<a for="header list">contains</a> whose <a for=header>name</a> is <var>name</var>, run these
substeps:
<ol>
<li><p>Let <var>extract</var> be the result of <a>extracting header values</a> from
<var>header</var>.
<li><p>If <var>extract</var> is failure, then return failure.
<li><p>Append each <a for=header>value</a> in <var>extract</var>, in order, to <var>values</var>.
</ol>
<li><p>Return <var>values</var>.
</ol>
<p>To
<dfn export for="header list" lt="extract a MIME type|extracting a MIME type" id=concept-header-extract-mime-type>extract a MIME type</dfn>
from a <a for=/>header list</a> (<var>headers</var>), run these steps:
<ol>
<li><p>Let <var>mimeType</var> be the result of <a>extracting header list values</a> given
`<code>Content-Type</code>` and <var>headers</var>.
<li><p>If <var>mimeType</var> is null or failure, then return the empty byte sequence.
<li><p>Return <var>mimeType</var>, <a lt="byte-lowercase">byte-lowercased</a>.
</ol>
<hr>
<p>A <dfn id=default-user-agent-value export>default `<code>User-Agent</code>` value</dfn> is a
user-agent-defined <a for=header>value</a> for the
`<code>User-Agent</code>` <a for=/>header</a>.
<h4 id=statuses>Statuses</h4>
<p>A <dfn export id=concept-status>status</dfn> is a code.
<p>A <dfn export>null body status</dfn> is a <a for=/>status</a> that is <code>101</code>,
<code>204</code>, <code>205</code>, or <code>304</code>.
<p>An <dfn export>ok status</dfn> is any <a for=/>status</a> in the range <code>200</code> to
<code>299</code>, inclusive.
<p>A <dfn export>redirect status</dfn> is a <a for=/>status</a> that is <code>301</code>,
<code>302</code>, <code>303</code>, <code>307</code>, or <code>308</code>.
<h4 id=bodies>Bodies</h4>
<p>A <dfn export id=concept-body>body</dfn> consists of:
<ul>
<li><p>A <dfn export for=body id=concept-body-stream>stream</dfn> (null or a {{ReadableStream}}
object).
<li><p>A <dfn export for=body id=concept-body-transmitted>transmitted bytes</dfn>
(an integer), initially 0.
<li><p>A <dfn export for=body id=concept-body-total-bytes>total bytes</dfn> (an
integer), initially 0.
<li><p>A <dfn export for=body id=concept-body-source>source</dfn>, initially null.
</ul>
<p>A <a for=/>body</a> <var>body</var> is said to be
<dfn export for=body id=concept-body-done>done</dfn> if <var>body</var> is null or
<var>body</var>'s <a for=body>stream</a> is
<a for=ReadableStream>closed</a> or
<a for=ReadableStream>errored</a>.
<p>To <dfn export for=body id=concept-body-wait>wait</dfn> for a
<a for=/>body</a> <var>body</var>, wait for <var>body</var> to be
<a for=body>done</a>.
<p>To <dfn export for=body id=concept-body-clone>clone</dfn> a
<a for=/>body</a> <var>body</var>, run these steps:
<ol>
<li><p>Let «<var>out1</var>, <var>out2</var>» be the result of
<a lt=tee for=ReadableStream>teeing</a> <var>body</var>'s <a for=body>stream</a>.
<li><p>Set <var>body</var>'s <a for=body>stream</a> to <var>out1</var>.
<li><p>Return a <a for=/>body</a> whose
<a for=body>stream</a> is <var>out2</var> and other members are copied from
<var>body</var>.
</ol>
<p>To <dfn 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. [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]]
</ol>
<!-- XXX no hook in HTTP -->
<h4 id=requests>Requests</h4>
<p>The input to <a for=/>fetch</a> is a
<dfn export id=concept-request>request</dfn>.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-method>method</dfn> (a
<a for=/>method</a>). Unless stated otherwise it is
`<code>GET</code>`.
<p class="note no-backref">This can be updated during redirects to `<code>GET</code>` as
described in <a>HTTP fetch</a>.
<p>A <a for=/>request</a> has an associated <dfn export for=request id=concept-request-url>url</dfn>
(a <a for=/>URL</a>).
<p class="note no-backref">Implementations are encouraged to make this a pointer to the first
<a for=/>URL</a> in <a for=/>request</a>'s <a for=request>url list</a>. It is provided as a distinct
field solely for the convenience of other standards hooking into Fetch.
<p>A <a for=/>request</a> has an associated
<dfn export>local-URLs-only flag</dfn>. Unless stated otherwise it is
unset.
<p>A <a for=/>request</a> has an associated
<dfn export>sandboxed-storage-area-URLs flag</dfn>. Unless stated
otherwise it is unset.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-header-list>header list</dfn> (a
<a for=/>header list</a>). Unless stated otherwise it is empty.
<p>A <a for=/>request</a> has an associated
<dfn id=unsafe-request-flag export for=request>unsafe-request flag</dfn>. Unless stated otherwise it
is unset.
<p class="note no-backref">The <a>unsafe-request flag</a> is set by APIs such as
<a><code>fetch()</code></a> and
{{XMLHttpRequest}} to ensure a
<a>CORS-preflight fetch</a> is done based on the supplied
<a for=request>method</a> and
<a for=request>header list</a>. It does not free an API from
outlawing <a>forbidden methods</a> and
<a>forbidden header names</a>.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-body>body</dfn> (null or a
<a for=/>body</a>). Unless stated otherwise it is null.
<p class="note no-backref">This can be updated during redirects to null as described in
<a>HTTP fetch</a>.
<hr>
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-client>client</dfn> (null or an
<a>environment settings object</a>).
<p>A <a for=/>request</a> has an associated
<dfn id=concept-request-reserved-client export for=request>reserved client</dfn>
(null, an <a>environment</a>, or an
<a>environment settings object</a>). Unless stated otherwise it is null.
<p class="note no-backref">This is only used by <a>navigation requests</a> and worker
requests, but not service worker requests. It references an
<a>environment</a> for a <a>navigation request</a> and an
<a>environment settings object</a> for a worker request.
<p>A <a for=/>request</a> has an associated
<dfn id=concept-request-target-client-id export for=request>target client id</dfn>
(a string). Unless stated otherwise it is the empty string.
<p class="note no-backref">This is only used by <a>navigation requests</a>. It is the
<a for="environment">id</a> of the
<a for="environment">target browsing context</a>'s
<a>active document</a>'s
<a>environment settings object</a>.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-window>window</dfn>
("<code>no-window</code>", "<code>client</code>", or an
<a>environment settings object</a> whose
<a for="environment settings object">global object</a> is a
{{Window}} 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
<a for=/>request</a>'s <a for=request>client</a> during
<a lt=fetch for=/>fetching</a>. It provides a convenient way for standards to not have to
explicitly set <a for=/>request</a>'s
<a for=request>window</a>.
<p id=keep-alive-flag>A <a for=/>request</a> has an associated
<dfn for=request export>keepalive flag</dfn>. Unless stated otherwise it is unset.
<p class="note no-backref">This can be used to allow the request to outlive the
<a>environment settings object</a>, e.g.,
<code>navigator.sendBeacon</code> and the HTML <code>img</code> element set this flag. Requests with
this flag set are subject to additional processing requirements.
<p>A <a for=/>request</a> has an associated <dfn for=request export>service-workers mode</dfn>, that
is "<code>all</code>" or "<code>none</code>". Unless stated otherwise it is "<code>all</code>".
<div class=note>
<p>This determines which service workers will receive a {{fetch!!event}} event for this fetch.
<dl>
<dt>"<code>all</code>"
<dd>Relevant service workers will get a {{fetch!!event}} event for this fetch.
<dt>"<code>none</code>"
<dd>No service workers will get events for this fetch.
</dd>
</div>
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-initiator>initiator</dfn>, which is
the empty string,
"<code>download</code>",
"<code>imageset</code>",
"<code>manifest</code>", or
"<code>xslt</code>". Unless stated otherwise it is the empty string.
<p class="note no-backref">A <a for=/>request</a>'s
<a for=request>initiator</a> is not particularly granular for
the time being as other specifications do not require it to be. It is primarily a
specification device to assist defining CSP and Mixed Content. It is not exposed to
JavaScript. [[!CSP]] [[!MIX]]
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-destination>destination</dfn>, which is
the empty string,
"<code>audio</code>",
"<code>audioworklet</code>",
"<code>document</code>",
"<code>embed</code>",
"<code>font</code>",
"<code>image</code>",
"<code>manifest</code>",
"<code>object</code>",
"<code>paintworklet</code>",
"<code>report</code>",
"<code>script</code>",
"<code>serviceworker</code>",
"<code>sharedworker</code>",
"<code>style</code>",
"<code>track</code>",
"<code>video</code>",
"<code>worker</code>", or
"<code>xslt</code>". Unless stated otherwise it is the empty string.
<!-- Dependencies:
* CSP: https://w3c.github.io/webappsec-csp/#effective-directive-for-a-request
* Mixed Content: https://w3c.github.io/webappsec-mixed-content/#should-block-fetch
* Preload: https://w3c.github.io/preload/#processing
* SRI: https://w3c.github.io/webappsec-subresource-integrity/#apply-algorithm-to-request
* HTML -->
<p>A <a for=/>request</a>'s <a for=request>destination</a> is
<dfn export for=request/destination>script-like</dfn> if it is "<code>audioworklet</code>",
"<code>paintworklet</code>", "<code>script</code>", "<code>serviceworker</code>",
"<code>sharedworker</code>", or "<code>worker</code>".
<p class=warning>Algorithms that use <a for=request/destination>script-like</a> should also consider
"<code>xslt</code>" as that too can cause script execution. It is not included in the list as it is
not always relevant and might require different behavior.
<div class=note>
<p>The following table illustrates the relationship between a <a for=/>request</a>'s
<a for=request>initiator</a>, <a for=request>destination</a>, CSP directives, and features.
<table>
<tbody><tr>
<th><a lt=initiator for=request>Initiator</a>
<th><a lt=destination for=request>Destination</a>
<th>CSP directive
<th>Features
<tr>
<td rowspan=18>""
<td>"<code>report</code>"
<td rowspan=2>—
<td>CSP, NEL reports.
<tr>
<td>"<code>document</code>"
<td>HTML's navigate algorithm.
<tr>
<td>"<code>document</code>"
<td><code>child-src</code>
<td>HTML's <code><iframe></code> and <code><frame></code>
<tr>
<td>""
<td><code>connect-src</code>
<td><code>navigator.sendBeacon()</code>, <code>EventSource</code>,
HTML's <code>ping=""</code>, <a><code>fetch()</code></a>,
<code>XMLHttpRequest</code>, <code>WebSocket</code>, Cache API?
<tr>
<td>"<code>object</code>"
<td><code>object-src</code>
<td>HTML's <code><object></code>
<tr>
<td>"<code>embed</code>"
<td><code>object-src</code>
<td>HTML's <code><embed></code>
<tr>
<td>"<code>audio</code>"
<td><code>media-src</code>
<td>HTML's <code><audio></code>
<tr>
<td>"<code>font</code>"
<td><code>font-src</code>
<td>CSS' <code>@font-face</code>
<tr>
<td>"<code>image</code>"
<td><code>img-src</code>
<td>HTML's <code><img src></code>, <code>/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>"<code>audioworklet</code>"
<td><code>script-src</code>
<td><code>audioWorklet.addModule()</code>
<tr>
<td>"<code>paintworklet</code>"
<td><code>script-src</code>
<td><code>CSS.paintWorklet.addModule()</code>
<tr>
<td>"<code>script</code>"
<td><code>script-src</code>
<td>HTML's <code><script></code>, <code>importScripts()</code>
<tr>
<td>"<code>serviceworker</code>"
<td><code>child-src</code>, <code>script-src</code>, <code>worker-src</code>
<td><code>navigator.serviceWorker.register()</code>
<tr>
<td>"<code>sharedworker</code>"
<td><code>child-src</code>, <code>script-src</code>, <code>worker-src</code>
<td><code>SharedWorker</code>
<tr>
<td>"<code>worker</code>"
<td><code>child-src</code>, <code>script-src</code>, <code>worker-src</code>
<td><code>Worker</code>
<tr>
<td>"<code>style</code>"
<td><code>style-src</code>
<td>HTML's <code><link rel=stylesheet></code>, CSS' <code>@import</code>
<tr>
<td>"<code>track</code>"
<td><code>media-src</code>
<td>HTML's <code><track></code>
<tr>
<td>"<code>video</code>"
<td><code>media-src</code>
<td>HTML's <code><video></code> element
<tr>
<td>"<code>download</code>"
<td>""
<td>—
<td>HTML's <code>download=""</code>, "Save Link As…" UI
<tr>
<td>"<code>imageset</code>"
<td>"<code>image</code>"
<td><code>img-src</code>
<td>HTML's <code><img srcset></code> and <code><picture></code>
<tr>
<td>"<code>manifest</code>"
<td>"<code>manifest</code>"
<td><code>manifest-src</code>
<td>HTML's <code><link rel=manifest></code>
<tr>
<td>"<code>xslt</code>"
<td>"<code>xslt</code>"
<td><code>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
<a for=/>request</a>'s
<a for=request>client</a>'s
<a for="environment settings object">responsible browsing context</a>'s
<a>ancestor browsing contexts</a>
for various CSP directives.
</div>
<hr>
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-priority>priority</dfn> (null or a
user-agent-defined object). Unless otherwise stated it is null.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-origin>origin</dfn>, which is
"<code>client</code>" or an <a for=/>origin</a>. Unless stated otherwise it is
"<code>client</code>".
<p class="note no-backref">"<code>client</code>" is changed to an
<a for=/>origin</a> during <a lt=fetch for=/>fetching</a>. It
provides a convenient way for standards to not have to set
<a for=/>request</a>'s <a for=request>origin</a>.
<a for=/>Request</a>'s <a for=request>origin</a> can be
changed during redirects too.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-referrer>referrer</dfn>, which is
"<code>no-referrer</code>", "<code>client</code>", or a <a for=/>URL</a>. 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
<a for=/>URL</a> during <a lt=fetch for=/>fetching</a>. It provides a convenient way for standards
to not have to set <a for=/>request</a>'s <a for=request>referrer</a>.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-referrer-policy>referrer policy</dfn>, which is a
<a for=/>referrer policy</a>. Unless stated otherwise it is the empty string. [[!REFERRER]]
<p class="note no-backref">This can be used to override a referrer policy associated with an
<a>environment settings object</a>.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-client-hints-list>client hints list</dfn>,
which is a <a lt="client hints list" for=client>client-hints list</a>. 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 <a>environment settings object</a>.
[[!CLIENT-HINTS]]
<p>A <a for=/>request</a> has an associated
<dfn id=synchronous-flag export for=request>synchronous flag</dfn>. Unless stated otherwise it is
unset.
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-mode>mode</dfn>, which is
"<code>same-origin</code>", "<code>cors</code>", "<code>no-cors</code>",