-
Notifications
You must be signed in to change notification settings - Fork 324
/
Overview.html
3284 lines (2599 loc) · 182 KB
/
Overview.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 href="//www.whatwg.org/style/specification" rel="stylesheet">
<link href="//resources.whatwg.org/logo-fetch.svg" rel="icon">
<div class="head">
<p><a class="logo" href="//www.whatwg.org/"><img alt="WHATWG" height="100" src="//resources.whatwg.org/logo-fetch.svg" width="100"></a>
<h1 id="cors">Fetch</h1>
<h2 class="no-num no-toc" id="living-standard-—-last-updated-12-august-2014">Living Standard — Last Updated 12 August 2014</h2>
<dl>
<dt>This Version:
<dd><a href="//fetch.spec.whatwg.org/">http://fetch.spec.whatwg.org/</a>
<dt>Participate:
<dd>Send feedback to <a href="http://www.whatwg.org/mailing-list">whatwg@whatwg.org</a> or
<a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=WHATWG&component=Fetch">file a bug</a>
(<a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WHATWG&component=Fetch&resolution=---">open bugs</a>)
<dd><a href="//wiki.whatwg.org/wiki/IRC">IRC: #whatwg on Freenode</a>
<dt>Version History:
<dd><a href="https://github.com/whatwg/fetch/commits">https://github.com/whatwg/fetch/commits</a>
<dt>Editor:
<dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
(<a href="http://www.mozilla.org/">Mozilla</a>)
<<a href="mailto:annevk@annevk.nl">annevk@annevk.nl</a>>
</dl>
<script async="" src="//resources.whatwg.org/file-bug.js"></script>
<p class="copyright"><a href="http://creativecommons.org/publicdomain/zero/1.0/" rel="license"><img alt="CC0" src="http://i.creativecommons.org/p/zero/1.0/80x15.png"></a>
To the extent possible under law, the editor has waived all copyright and
related or neighboring rights to this work. In addition, as of
12 August 2014, the editor has made this specification available
under the
<a href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0" rel="license">Open Web Foundation Agreement Version 1.0</a>,
which is available at
http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>The Fetch standard defines requests, responses, and the process that binds them;
fetching.
<h2 class="no-num no-toc" id="table-of-contents">Table of Contents</h2>
<!--begin-toc-->
<ol class="toc">
<li><a class="no-num" href="#goals">Goals</a></li>
<li><a href="#conformance"><span class="secno">1 </span>Conformance</a></li>
<li><a href="#terminology"><span class="secno">2 </span>Terminology</a>
<ol class="toc">
<li><a href="#http"><span class="secno">2.1 </span>HTTP</a>
<ol class="toc">
<li><a href="#methods"><span class="secno">2.1.1 </span>Methods</a></li>
<li><a href="#terminology-headers"><span class="secno">2.1.2 </span>Headers</a></li>
<li><a href="#body"><span class="secno">2.1.3 </span>Body</a></li>
<li><a href="#requests"><span class="secno">2.1.4 </span>Requests</a></li>
<li><a href="#responses"><span class="secno">2.1.5 </span>Responses</a></ol></ol></li>
<li><a href="#http-extensions"><span class="secno">3 </span>HTTP extensions</a>
<ol class="toc">
<li><a href="#origin-header"><span class="secno">3.1 </span>`<code title="">Origin</code>` header</a></li>
<li><a href="#http-cors-protocol"><span class="secno">3.2 </span>CORS protocol</a>
<ol class="toc">
<li><a href="#general"><span class="secno">3.2.1 </span>General</a></li>
<li><a href="#http-requests"><span class="secno">3.2.2 </span>HTTP requests</a></li>
<li><a href="#http-responses"><span class="secno">3.2.3 </span>HTTP responses</a></li>
<li><a href="#http-new-header-syntax"><span class="secno">3.2.4 </span>HTTP new header syntax</a></ol></ol></li>
<li><a href="#fetching"><span class="secno">4 </span>Fetching</a>
<ol class="toc">
<li><a href="#basic-fetch"><span class="secno">4.1 </span>Basic fetch</a></li>
<li><a href="#http-fetch"><span class="secno">4.2 </span>HTTP fetch</a></li>
<li><a href="#http-network-or-cache-fetch"><span class="secno">4.3 </span>HTTP network or cache fetch</a></li>
<li><a href="#cors-preflight-fetch"><span class="secno">4.4 </span>CORS preflight fetch</a></li>
<li><a href="#cors-preflight-cache"><span class="secno">4.5 </span>CORS preflight cache</a></li>
<li><a href="#cors-check"><span class="secno">4.6 </span>CORS check</a></ol></li>
<li><a href="#fetch-api"><span class="secno">5 </span>Fetch API</a>
<ol class="toc">
<li><a href="#headers-class"><span class="secno">5.1 </span>Headers class</a></li>
<li><a href="#body-stream-concept"><span class="secno">5.2 </span>Body stream concept</a></li>
<li><a href="#request-class"><span class="secno">5.3 </span>Request class</a></li>
<li><a href="#response-class"><span class="secno">5.4 </span>Response class</a></li>
<li><a href="#structured-cloning-of-headers,-fetchbodystream,-request,-and-response-objects"><span class="secno">5.5 </span>Structured cloning of <code>Headers</code>, <code>FetchBodyStream</code>, <code>Request</code>, and <code>Response</code> objects</a></li>
<li><a href="#fetch-method"><span class="secno">5.6 </span>Fetch method</a></ol></li>
<li><a class="no-num" href="#background-reading">Background reading</a>
<ol class="toc">
<li><a class="no-num" href="#http-header-layer-division">HTTP header layer division</a></li>
<li><a class="no-num" href="#atomic-http-redirect-handling">Atomic HTTP redirect handling</a></li>
<li><a class="no-num" href="#basic-safe-cors-protocol-setup">Basic safe CORS protocol setup</a></li>
<li><a class="no-num" href="#cors-protocol-and-http-caches">CORS protocol and HTTP caches</a></ol></li>
<li><a class="no-num" href="#references">References</a></li>
<li><a class="no-num" href="#acknowledgments">Acknowledgments</a></ol>
<!--end-toc-->
<h2 class="no-num" id="goals">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
<a class="informative" href="#refsHTML">[HTML]</a>
<li>CORS <a class="informative" href="#refsCORS">[CORS]</a>
<li>HTTP `<code title="http-origin"><a href="#http-origin">Origin</a></code>` header semantics
<a class="informative" href="#refsORIGIN">[ORIGIN]</a>
</ul>
<p>Unifying fetching provides consistent handling of:
<ul class="brief">
<li>URL schemes
<li>Redirects
<li>Cross-origin semantics
<li>CSP <a href="#refsCSP">[CSP]</a>
<li>Service Workers <a href="#refsSW">[SW]</a>
<li>Mixed Content <a href="#refsMIX">[MIX]</a>
<li>`<code title="">Referer</code>` <a href="#refsREFERRER">[REFERRER]</a>
</ul>
<h2 id="conformance"><span class="secno">1 </span>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.
<a href="#refsRFC2119">[RFC2119]</a>
<h2 id="terminology"><span class="secno">2 </span>Terminology</h2>
<p>This specification uses terminology from the Encoding and URL Standards.
<a href="#refsENCODING">[ENCODING]</a>
<a href="#refsURL">[URL]</a>
<p>A <a class="external" href="http://encoding.spec.whatwg.org/#byte">byte</a> sequence with bytes in the range 0x00 to
0x7F is represented as a <a class="external" href="http://encoding.spec.whatwg.org/#utf-8">utf-8</a> encoded
<a class="external" href="http://encoding.spec.whatwg.org/#string">string</a> with code points in the range U+0000 to
U+007F. To avoid confusion with an actual string backticks are used.
<p class="example">"<code title="">true</code>" is a
<a class="external" href="http://encoding.spec.whatwg.org/#string">string</a>, while `<code title="">true</code>` is a
byte sequence.
<p>Comparing two byte sequences in a <dfn id="byte-case-insensitive">byte case-insensitive</dfn> manner means
comparing them exactly, byte for byte, except that the bytes in the range 0x41 to 0x5A are
considered to also match their corresponding byte in the range 0x61 to 0x7A.
<p>A <dfn id="case-insensitive-byte-sequence">case-insensitive byte sequence</dfn> is a byte sequence that when compared to
another byte sequence does so in a <a href="#byte-case-insensitive">byte case-insensitive</a> manner.
<p class="example">The
<a href="#case-insensitive-byte-sequence" title="case-insensitive byte sequence">case-insensitive byte sequences</a>
`<code title="">Content-Type</code>` and `<code title="">content-TYPE</code>` are equal.
<p>To <dfn id="byte-lowercase">byte lowercase</dfn> a byte sequence, increase each byte it contains, in the
range 0x41 to 0x5A, by 0x20.
<h3 id="http"><span class="secno">2.1 </span>HTTP</h3>
<p>While <a href="#concept-fetch" title="concept-fetch">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. via <code title="">data</code> URL).
<h4 id="methods"><span class="secno">2.1.1 </span>Methods</h4>
<p>A <dfn id="concept-method" title="concept-method">method</dfn> is a byte sequence that matches the
<a class="external" href="http://tools.ietf.org/html/rfc2616/#section-5.1.1">Method</a> token production.
<p>A <dfn id="simple-method">simple method</dfn> is a <a href="#concept-method" title="concept-method">method</a> that is
`<code title="">GET</code>`, `<code title="">HEAD</code>`, or `<code title="">POST</code>`.
<p>A <dfn id="forbidden-method">forbidden method</dfn> is a <a href="#concept-method" title="concept-method">method</a> that is a
<a href="#byte-case-insensitive">byte case-insensitive</a> match for one of `<code title="">CONNECT</code>`,
`<code title="">TRACE</code>`, and `<code title="">TRACK</code>`.
<a href="#refsHTTPVERBSEC">[HTTPVERBSEC]</a>
<p>A <dfn id="useful-method">useful method</dfn> is a <a href="#concept-method" title="concept-method">method</a> that is not a
<a href="#forbidden-method">forbidden method</a>.
<h4 id="terminology-headers"><span class="secno">2.1.2 </span>Headers</h4>
<p>A <dfn id="concept-header-list" title="concept-header-list">header list</dfn> consists of zero or more
<a href="#concept-header" title="concept-header">headers</a>.
<p>To <dfn id="concept-header-list-append" title="concept-header-list-append">append</dfn> a
<a href="#concept-header-name" title="concept-header-name">name</a>/<a href="#concept-header-value" title="concept-header-value">value</a>
(<var title="">name</var>/<var title="">value</var>) pair to a
<a href="#concept-header-list" title="concept-header-list">header list</a> (<var title="">list</var>), append a new
<a href="#concept-header" title="concept-header">header</a> whose <a href="#concept-header-name" title="concept-header-name">name</a>
is <var title="">name</var>, <a href="#byte-lowercase" title="byte lowercase">byte lowercased</a>, and
<a href="#concept-header-value" title="concept-header-value">value</a> is <var title="">value</var>, to
<var title="">list</var>.
<p>To <dfn id="concept-header-list-delete" title="concept-header-list-delete">delete</dfn> a
<a href="#concept-header-name" title="concept-header-name">name</a> (<var title="">name</var>) from a
<a href="#concept-header-list" title="concept-header-list">header list</a> (<var title="">list</var>), remove all
<a href="#concept-header" title="concept-header">headers</a> whose
<a href="#concept-header-name" title="concept-header-name">name</a> is <var title="">name</var>,
<a href="#byte-lowercase" title="byte lowercase">byte lowercased</a>, from <var title="">list</var>.
<p>To <dfn id="concept-header-list-set" title="concept-header-list-set">set</dfn> a
<a href="#concept-header-name" title="concept-header-name">name</a>/<a href="#concept-header-value" title="concept-header-value">value</a>
(<var title="">name</var>/<var title="">value</var>) pair in a
<a href="#concept-header-list" title="concept-header-list">header list</a> (<var title="">list</var>), run these
steps:
<ol>
<li><p><a href="#byte-lowercase">Byte lowercase</a> <var title="">name</var>.
<li><p>If there are any <a href="#concept-header" title="concept-header">headers</a> in
<var title="">list</var> whose <a href="#concept-header-name" title="concept-header-name">name</a> is
<var title="">name</var>, set the <a href="#concept-header-value" title="concept-header-value">value</a> of the first
such <a href="#concept-header" title="concept-header">header</a> to <var title="">value</var> and remove the
others.
<li><p>Otherwise, append a new <a href="#concept-header" title="concept-header">header</a> whose
<a href="#concept-header-name" title="concept-header-name">name</a> is <var title="">name</var> and
<a href="#concept-header-value" title="concept-header-value">value</a> is <var title="">value</var>, to
<var title="">list</var>.
</ol>
<p>To <dfn id="concept-header-list-combine" title="concept-header-list-combine">combine</dfn> a
<a href="#concept-header-name" title="concept-header-name">name</a>/<a href="#concept-header-value" title="concept-header-value">value</a>
(<var title="">name</var>/<var title="">value</var>) pair in a
<a href="#concept-header-list" title="concept-header-list">header list</a> (<var title="">list</var>), run these
steps:
<ol>
<li><p><a href="#byte-lowercase">Byte lowercase</a> <var title="">name</var>.
<li><p>If there are any <a href="#concept-header" title="concept-header">headers</a> in
<var title="">list</var> whose <a href="#concept-header-name" title="concept-header-name">name</a> is
<var title="">name</var>, set the <a href="#concept-header-value" title="concept-header-value">value</a> of the first
such <a href="#concept-header" title="concept-header">header</a> to
<a href="#concept-header-value" title="concept-header-value">value</a>, followed by 0x2C 0x20, followed by <var title="">value</var>.
<li><p>Otherwise, append a new <a href="#concept-header" title="concept-header">header</a> whose
<a href="#concept-header-name" title="concept-header-name">name</a> is <var title="">name</var> and
<a href="#concept-header-value" title="concept-header-value">value</a> is <var title="">value</var>, to
<var title="">list</var>.
</ol>
<p class="note no-backref"><a href="#concept-header-list-combine" title="concept-header-list-combine">Combine</a> solely
exists for <code class="external"><a href="http://xhr.spec.whatwg.org/#xmlhttprequest">XMLHttpRequest</a></code>.
<hr>
<p>A <dfn id="concept-header" title="concept-header">header</dfn> consists of a
<dfn id="concept-header-name" title="concept-header-name">name</dfn> and <dfn id="concept-header-value" title="concept-header-value">value</dfn>.
A <a href="#concept-header-name" title="concept-header-name">name</a> is a
<a href="#case-insensitive-byte-sequence">case-insensitive byte sequence</a> that matches the
<a class="external" href="http://tools.ietf.org/html/rfc2616/#section-4.2">field-name</a> token production. A
<a href="#concept-header-value" title="concept-header-value">value</a> is a byte sequence that matches the
<a class="external" href="http://tools.ietf.org/html/rfc2616/#section-4.2">field-value</a> token production and contains no 0x0A or
0x0D bytes.
<p class="note">Allowing 0x0A and 0x0D bytes can lead to reparsing issues.
<hr>
<p>A <dfn id="simple-header">simple header</dfn> is a <a href="#concept-header" title="concept-header">header</a> whose
<a href="#concept-header-name" title="concept-header-name">name</a> is either one of `<code title="">Accept</code>`,
`<code title="">Accept-Language</code>`, and `<code title="">Content-Language</code>`, or whose
<a href="#concept-header-name" title="concept-header-name">name</a> is `<code title="">Content-Type</code>` and
<a href="#concept-header-value" title="concept-header-value">value</a>,
<a href="#concept-header-parse" title="concept-header-parse">once parsed</a>, has a MIME type (ignoring parameters)
that is one of `<code title="">application/x-www-form-urlencoded</code>`,
`<code title="">multipart/form-data</code>`, and `<code title="">text/plain</code>`.
<!-- XXX * needs better xref
* ignoring parameters has been the standard for a long time now
* interesting test: "Content-Type: text/plain;" -->
<p>A <dfn id="forbidden-header-name">forbidden header name</dfn> is a <a href="#concept-header" title="concept-header">header</a>
<a href="#concept-header-name" title="concept-header-name">name</a> that either 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"><a href="#http-origin">Origin</a></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="">User-Agent</code>`
<li>`<code title="">Via</code>`
</ul>
<p>or starts with `<code title="">Proxy-</code>` or `<code title="">Sec-</code>`
(including when it is 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.
<a href="#concept-header-name" title="concept-header-name">Names</a> starting with `<code title="">Sec-</code>` are
reserved to allow new <a href="#concept-header" title="concept-header">headers</a> to be minted that are safe
from APIs using <a href="#concept-fetch" title="concept-fetch">fetch</a> that allow control over
<a href="#concept-header" title="concept-header">headers</a> by developers, such as
<code class="external"><a href="http://xhr.spec.whatwg.org/#xmlhttprequest">XMLHttpRequest</a></code>.
<a class="informative" href="#refsXHR">[XHR]</a>
<p>A <dfn id="forbidden-response-header-name">forbidden response header name</dfn> is a <a href="#concept-header" title="concept-header">header</a>
<a href="#concept-header-name" title="concept-header-name">name</a> that is one of:
<ul class="brief">
<li>`<code title="">Set-Cookie</code>`
<li>`<code title="">Set-Cookie2</code>`
</ul>
<hr>
<p>To <dfn id="concept-header-parse" title="concept-header-parse">parse a header value</dfn> given a
<a href="#concept-header-name" title="concept-header-name">name</a> (<var title="">name</var>) and either a
<a href="#concept-header" title="concept-header">header</a> or a
<a href="#concept-header-list" title="concept-header-list">header list</a> (<var title="">headers</var>), run these
steps:
<ol>
<li><p>If <var title="">name</var> is not in <var title="">headers</var>, return null.
<li>
<p>If the ABNF for <var title="">name</var> allows a single
<a href="#concept-header" title="concept-header">header</a> and <var title="">headers</var> contains more than
one, return failure.
<p class="note no-backref">That if you require different error handling, you need to
extract the desired <a href="#concept-header" title="concept-header">header</a> first.
<li><p>If parsing all the <a href="#concept-header" title="concept-header">headers</a>
<a href="#concept-header-name" title="concept-header-name">named</a> <var title="">name</var> in
<var title="">headers</var>, per the ABNF for <var title="">name</var>, failed, return failure.
<li><p>Return one or more <a href="#concept-header-value" title="concept-header-value">values</a> resulting from
parsing all the <a href="#concept-header" title="concept-header">headers</a>
<a href="#concept-header-name" title="concept-header-name">named</a> <var title="">name</var> in
<var title="">headers</var>, per the ABNF for <var title="">name</var>.
</ol>
<p>To <dfn id="concept-header-extract-mime-type" title="concept-header-extract-MIME-type">extract a MIME type</dfn> from a
<a href="#concept-header-list" title="concept-header-list">header list</a> (<var title="">headers</var>), run these
steps:
<ol>
<li><p>Let <var title="">MIMEType</var> be the result of
<a href="#concept-header-parse" title="concept-header-parse">parsing</a> `<code title="">Content-Type</code>` in
<var title="">headers</var>.
<li><p>If <var title="">MIMEType</var> is null or failure, return the empty byte sequence.
<li><p>Return <var title="">MIMEType</var>,
<a href="#byte-lowercase" title="byte lowercase">byte lowercased</a>.
</ol>
<h4 id="body"><span class="secno">2.1.3 </span>Body</h4>
<p>A <dfn id="concept-body" title="concept-body">body</dfn> is a byte stream. It has an associated
<dfn id="concept-body-transmitted" title="concept-body-transmitted">transmitted</dfn> and
<dfn id="concept-body-length" title="concept-body-length">length</dfn>. Unless stated otherwise these are 0.
<p>To <dfn id="handle-content-codings">handle content codings</dfn> given <var title="">codings</var> and
<var title="">bytes</var>, run these substeps:
<ol>
<li><p>If <var title="">codings</var> are not supported, return <var title="">bytes</var>.
<li><p>Return the result of decoding bytes with the given
<var title="">codings</var> as explained in HTTP. <a href="#refsHTTP">[HTTP]</a>
</ol>
<!-- XXX no hook in HTTP -->
<h4 id="requests"><span class="secno">2.1.4 </span>Requests</h4>
<p>The input to <a href="#concept-fetch" title="concept-fetch">fetch</a> is a
<dfn id="concept-request" title="concept-request">request</dfn>.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-method" title="concept-request-method">method</dfn> (a
<a href="#concept-method" title="concept-method">method</a>). Unless stated otherwise it is
`<code title="">GET</code>`.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-url" title="concept-request-url">url</dfn> (a
<a class="external" href="http://url.spec.whatwg.org/#concept-url" title="concept-url">URL</a>).
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="sandboxed-storage-area-urls-flag">sandboxed storage area URLs flag</dfn>. Unless stated otherwise it is unset.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-header-list" title="concept-request-header-list">header list</dfn> (a
<a href="#concept-header-list" title="concept-header-list">header list</a>). Unless stated otherwise it is empty.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="unsafe-request-flag">unsafe request flag</dfn>. Unless stated otherwise it is unset.
<p class="note no-backref">The <a href="#unsafe-request-flag">unsafe request flag</a> is set by APIs such as
<code title="dom-global-fetch"><a href="#dom-global-fetch">fetch()</a></code> and
<code class="external"><a href="http://xhr.spec.whatwg.org/#xmlhttprequest">XMLHttpRequest</a></code> to ensure a
<a href="#cors-preflight-fetch-0">CORS preflight fetch</a> is done based on the supplied
<a href="#concept-request-method" title="concept-request-method">method</a> and
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>. It does not free an API from
outlawing <a href="#forbidden-method" title="forbidden method">forbidden methods</a> and
<a href="#forbidden-header-name" title="forbidden header name">forbidden header names</a>.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-body" title="concept-request-body">body</dfn> (null or a
<a href="#concept-body" title="concept-body">body</a>). Unless stated otherwise it is null.
<hr>
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-client" title="concept-request-client">client</dfn> (a
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#javascript-global-environment">JavaScript global environment</a>).
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="skip-service-worker-flag">skip service worker flag</dfn>. Unless stated otherwise it is unset.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-context" title="concept-request-context">context</dfn>, which is one of
<i title="">audio</i>,
<i title="">beacon</i>,
<i title="">cspreport</i>,
<i title="">download</i>,
<i title="">embed</i>,
<i title="">eventsource</i>,
<i title="">favicon</i>,
<i title="">fetch</i>,
<i title="">font</i>,
<i title="">form</i>,
<i title="">frame</i>,
<i title="">hyperlink</i>,
<i title="">iframe</i>,
<i title="">image</i>,
<i title="">imageset</i>,
<i title="">import</i>,
<i title="">internal</i>,
<i title="">location</i>,
<i title="">manifest</i>,
<i title="">object</i>,
<i title="">ping</i>,
<i title="">plugin</i>,
<i title="">prefetch</i>,
<i title="">script</i>,
<i title="">serviceworker</i>,
<i title="">sharedworker</i>,
<i title="">subresource</i>,
<i title="">style</i>,
<i title="">track</i>,
<i title="">video</i>,
<i title="">worker</i>,
<i title="">xmlhttprequest</i>, and
<i title="">xslt</i>.
<!--
http://wiki.whatwg.org/wiki/Contexts
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy
-->
<!--
<p>A <dfn>client request</dfn> is a <span title=concept-request>request</span> whose
<span title=concept-request-context>context</span> is one of <i title>child</i>,
<i title>navigate</i>, <i title>popup</i>, and <i title>sharedworker</i>.
<p>A <dfn>resource request</dfn> is a <span title=concept-request>request</span> that is
not a <span>client request</span>.
-->
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-context-frame-type" title="concept-request-context-frame-type">context frame type</dfn>, which is one of
<i title="">auxiliary</i>, <i title="">top-level</i>, <i title="">nested</i>, and
<i title="">none</i>. Unless stated otherwise it is <i title="">none</i>.
<p class="XXX">Remove <i title="">auxiliary</i>? Not sure it is distinctive enough.
<div class="note">
<p>The following table illustrates the relationship between a
<a href="#concept-request" title="concept-request">request</a>'s
<a href="#concept-request-context" title="concept-request-context">context</a>, its
<a href="#concept-request-context-frame-type" title="concept-request-context-frame-type">context frame type</a>, and
CSP directives:
<table>
<tr>
<th><a href="#concept-request-context" title="concept-request-context">context</a>
<th><a href="#concept-request-context-frame-type" title="concept-request-context-frame-type">context frame type</a>
<th>CSP directive
<th>Platform feature example
<tr>
<td><i title="">audio</i>
<td><i title="">none</i>
<td><code title="">media-src</code>
<td>HTML's <code>audio</code> element
<tr>
<td><i title="">beacon</i>
<td><i title="">none</i>
<td><code title="">connect-src</code>
<td><code>navigator.sendBeacon()</code>
<tr>
<td><i title="">cspreport</i>
<td><i title="">none</i>
<td><code title="">connect-src</code>
<td>CSP's report feature
<tr>
<td><i title="">download</i>
<td><i title="">none</i>
<td>—
<td>HTML's <code>a</code> element when its <code>download</code> attribute is set
<tr>
<td><i title="">embed</i>
<td><i title="">none</i>
<td><code title="">object-src</code>
<td>HTML's <code>embed</code> element
<tr>
<td><i title="">eventsource</i>
<td><i title="">none</i>
<td><code title="">connect-src</code>
<td><code>EventSource</code>
<tr>
<td><i title="">favicon</i>
<td><i title="">none</i>
<td>—
<td><code title="">/favicon.ico</code> resource
<tr>
<td><i title="">fetch</i>
<td><i title="">none</i>
<td><code title="">connect-src</code>
<td><code title="dom-global-fetch"><a href="#dom-global-fetch">fetch()</a></code>
<tr>
<td><i title="">font</i>
<td><i title="">none</i>
<td><code title="">font-src</code>
<td>CSS' <code>@font-face</code>
<tr>
<td><i title="">form</i>
<td>any but <i title="">none</i>
<td><code title="">form-action</code>, potentially <code title="">child-src</code>
<td>HTML's <code>form</code> element
<tr>
<td><i title="">frame</i>
<td><i title="">nested</i>
<td><code title="">child-src</code>
<td>HTML's <code>frame</code> element
<tr>
<td><i title="">hyperlink</i>
<td>any but <i title="">none</i>
<td>potentially <code title="">child-src</code>
<td>HTML's <code>a</code> element
<tr>
<td><i title="">iframe</i>
<td><i title="">nested</i>
<td><code title="">child-src</code>
<td>HTML's <code>iframe</code> element
<tr>
<td><i title="">image</i>
<td><i title="">none</i>
<td><code title="">img-src</code>
<td>SVG's <code>image</code> element
<tr>
<td><i title="">imageset</i>
<td><i title="">none</i>
<td><code title="">img-src</code>
<td>HTML's <code>picture</code> element
<tr>
<td><i title="">import</i>
<td><i title="">none</i>
<td><code title="">script-src</code>
<td>HTML's <code>link</code> element when its <code>rel</code> attribute is set to
"<code>import</code>"
<tr>
<td><i title="">internal</i>
<td>any
<td>
<td>User agent actions such as refresh, back, forward; other user agent usage
<tr>
<td><i title="">location</i>
<td>any but <code title="">none</code>
<td>potentially <code title="">child-src</code>
<td><code title="">window.location</code>
<tr>
<td><i title="">manifest</i>
<td><i title="">none</i>
<td>—
<td>HTML's <code>link</code> element when its <code>rel</code> attribute is set to
"<code>manifest</code>"
<tr>
<td><i title="">object</i>
<td><i title="">none</i>
<td><code title="">object-src</code>
<td>HTML's <code>object</code> element
<tr>
<td><i title="">ping</i>
<td><i title="">none</i>
<td><code title="">connect-src</code>
<td>HTML's <code>ping</code> attribute
<tr>
<td><i title="">plugin</i>
<td><i title="">none</i>
<td>—
<td>A <a href="#concept-fetch" title="concept-fetch">fetch</a> from a plugin
<tr>
<td><i title="">prefetch</i>
<td><i title="">none</i>
<td>—
<td>HTML's <code>link</code> element when its <code>rel</code> attribute is set to
"<code>prefetch</code>"
<tr>
<td><i title="">script</i>
<td><i title="">none</i>
<td><code title="">script-src</code>
<td>HTML's <code>script</code> element
<tr>
<td><i title="">serviceworker</i>
<td><i title="">none</i>
<td>—
<td><code title="">navigator.serviceWorker.register()</code>
<tr>
<td><i title="">sharedworker</i>
<td><i title="">none</i>
<td><code title="">child-src</code>
<td><code>SharedWorker</code>
<tr>
<td><i title="">subresource</i>
<td><i title="">none</i>
<td>—
<td>HTML's <code>link</code> element when its <code>rel</code> attribute is set to
"<code>subresource</code>"
<tr>
<td><i title="">style</i>
<td><i title="">none</i>
<td><code title="">style-src</code>
<td>HTML's <code>link</code> element when its <code>rel</code> attribute is set to
"<code>stylesheet</code>"
<tr>
<td><i title="">track</i>
<td><i title="">none</i>
<td><code title="">media-src</code>
<td>HTML's <code>track</code> element
<tr>
<td><i title="">video</i>
<td><i title="">none</i>
<td><code title="">media-src</code>
<td>HTML's <code>video</code> element
<tr>
<td><i title="">worker</i>
<td><i title="">none</i>
<td><code title="">child-src</code>
<td><code>Worker</code>
<tr>
<td><i title="">xmlhttprequest</i>
<td><i title="">none</i>
<td><code title="">connect-src</code>
<td><code class="external"><a href="http://xhr.spec.whatwg.org/#xmlhttprequest">XMLHttpRequest</a></code>
<tr>
<td><i title="">xslt</i>
<td><i title="">none</i>
<td><code title="">script-src</code>
<td><code><?xml-stylesheet></code>
</table>
</div>
<hr>
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-origin" title="concept-request-origin">origin</dfn> (an
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#origin">origin</a>). Unless stated otherwise it is an
opaque identifier.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="force-origin-header-flag">force <code title="">Origin</code> header flag</dfn>. Unless stated otherwise it is unset.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="same-origin-data-url-flag">same-origin data URL flag</dfn>. Unless stated otherwise it is unset.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-referrer" title="concept-request-referrer">referrer</dfn>, which is <i title="">none</i>,
<i title="">client</i>, or a <a class="external" href="http://url.spec.whatwg.org/#concept-url" title="concept-url">URL</a>. Unless
stated otherwise it is <i title="">client</i>.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="authentication-flag">authentication flag</dfn>. Unless stated otherwise it is unset.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="synchronous-flag">synchronous flag</dfn>. Unless stated otherwise it is unset.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-mode" title="concept-request-mode">mode</dfn>, which is one of <i title="">same-origin</i>,
<i title="">no CORS</i>, <i title="">CORS</i>, and
<i title="">CORS-with-forced-preflight</i>. Unless stated otherwise, it is
<i title="">no CORS</i>.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</dfn>, which is
one of <i title="">omit</i>, <i title="">same-origin</i>, and <i title="">include</i>. Unless
stated otherwise, it is <i title="">omit</i>.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-use-url-credentials-flag" title="concept-request-use-url-credentials-flag">use URL credentials flag</dfn>.
Unless stated otherwise, it is unset.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-manual-redirect-flag" title="concept-request-manual-redirect-flag">manual redirect flag</dfn>. Unless stated
otherwise, it is unset.
<hr>
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-redirect-count" title="concept-request-redirect-count">redirect count</dfn>. Unless stated otherwise,
it is zero.
<p>A <a href="#concept-request" title="concept-request">request</a> has an associated
<dfn id="concept-request-response-tainting" title="concept-request-response-tainting">response tainting</dfn>, which is one of
<i title="">basic</i>, <i title="">CORS</i>, and <i title="">opaque</i>. Unless stated otherwise,
it is <i title="">basic</i>.
<p class="note no-backref">A <a href="#concept-request" title="concept-request">request</a>'s
<a href="#concept-request-redirect-count" title="concept-request-redirect-count">redirect count</a> and
<a href="#concept-request-response-tainting" title="concept-request-response-tainting">response tainting</a> are used as
bookkeeping details by the <a href="#concept-fetch" title="concept-fetch">fetch</a> algorithm.
<h4 id="responses"><span class="secno">2.1.5 </span>Responses</h4>
<p>The result of <a href="#concept-fetch" title="concept-fetch">fetch</a> is a
<dfn id="concept-response" title="concept-response">response</dfn>. A <a href="#concept-response" title="concept-response">response</a>
evolves over time. That is, not all its fields are available straight away.
<p>A <a href="#concept-response" title="concept-response">response</a> has an associated
<dfn id="concept-response-type" title="concept-response-type">type</dfn> which is one of
<i title="">basic</i>,
<i title="">CORS</i>,
<i title="">default</i>,
<i title="">error</i>, and
<i title="">opaque</i>.
Unless stated otherwise, it is <i title="">default</i>.
<p>A <a href="#concept-response" title="concept-response">response</a> can have an associated
<dfn id="concept-response-termination-reason" title="concept-response-termination-reason">termination reason</dfn> which is one of
<i title="">end-user abort</i>, <i title="">fatal</i>, and <i title="">timeout</i>.
<p>A <a href="#concept-response" title="concept-response">response</a> has an associated
<dfn id="concept-response-url" title="concept-response-url">url</dfn>,
<dfn id="concept-response-status" title="concept-response-status">status</dfn>,
<dfn id="concept-response-status-message" title="concept-response-status-message">status message</dfn>,
<dfn id="concept-response-header-list" title="concept-response-header-list">header list</dfn>, and a
<dfn id="concept-response-body" title="concept-response-body">body</dfn>. Unless stated otherwise, a
<a href="#concept-response" title="concept-response">response</a>'s
<a href="#concept-response-url" title="concept-response-url">url</a> is null,
<a href="#concept-response-status" title="concept-response-status">status</a> is <code title="">200</code>,
<a href="#concept-response-status-message" title="concept-response-status-message">status message</a> is `<code title="">OK</code>`,
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a> is an empty
<a href="#concept-header-list" title="concept-header-list">header list</a>, and
<a href="#concept-response-body" title="concept-response-body">body</a> is null.
<hr>
<p>A <a href="#concept-response" title="concept-response">response</a> whose
<a href="#concept-response-type" title="concept-response-type">type</a> is <i title="">error</i> is known as a
<dfn id="concept-network-error" title="concept-network-error">network error</dfn>.
<p>A <a href="#concept-network-error" title="concept-network-error">network error</a> is a
<a href="#concept-response" title="concept-response">response</a> whose
<a href="#concept-response-status" title="concept-response-status">status</a> is always <code title="">0</code>,
<a href="#concept-response-status-message" title="concept-response-status-message">status message</a> is always the empty byte sequence,
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a> is aways an empty list, and
<a href="#concept-response-body" title="concept-response-body">body</a> is always null.
<!-- XXX Introduce concept-redirect and concept-redirect-location for navigate algorithm? -->
<hr>
<p>A <dfn id="concept-filtered-response" title="concept-filtered-response">filtered response</dfn> is a limited view on a
<a href="#concept-response" title="concept-response">response</a> that is not a
<a href="#concept-network-error" title="concept-network-error">network error</a>. This
<a href="#concept-response" title="concept-response">response</a> is referred to as the
<a href="#concept-filtered-response" title="concept-filtered-response">filtered response</a>'s associated
<dfn id="concept-internal-response" title="concept-internal-response">internal response</dfn>.
<p class="note no-backref">The <a href="#concept-fetch" title="concept-fetch">fetch</a> algorithm returns
such a view to ensure APIs do not accidentally leak information. If the information is
required, e.g. to feed image data to a decoder, the associated
<a href="#concept-internal-response" title="concept-internal-response">internal response</a> can be used.
<p>A <dfn id="concept-filtered-response-basic" title="concept-filtered-response-basic">basic filtered response</dfn> is a
<a href="#concept-filtered-response" title="concept-filtered-response">filtered response</a> whose
<a href="#concept-response-type" title="concept-response-type">type</a> is <i title="">basic</i>,
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a> excludes any
<a href="#concept-header" title="concept-header">headers</a> in
<a href="#concept-internal-response" title="concept-internal-response">internal response</a>'s
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a> whose
<a href="#concept-header-name" title="concept-header-name">name</a> is `<code title="">Set-Cookie</code>` or
`<code title="">Set-Cookie2</code>`.
<p>A <dfn id="concept-filtered-response-cors" title="concept-filtered-response-cors">CORS filtered response</dfn> is a
<a href="#concept-filtered-response" title="concept-filtered-response">filtered response</a> whose
<a href="#concept-response-type" title="concept-response-type">type</a> is <i title="">CORS</i>,
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a> excludes all
<a href="#concept-header" title="concept-header">headers</a> in
<a href="#concept-internal-response" title="concept-internal-response">internal response</a>'s
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a>, except those whose
<a href="#concept-header-name" title="concept-header-name">name</a> is either one of
`<code title="">Cache-Control</code>`, `<code title="">Content-Language</code>`,
`<code title="">Content-Type</code>`, `<code title="">Expires</code>`,
`<code title="">Last-Modified</code>`, and `<code title="">Pragma</code>`, and except those
whose <a href="#concept-header-name" title="concept-header-name">name</a> is one of the
<a href="#concept-header-value" title="concept-header-value">values</a> resulting from
<a href="#concept-header-parse" title="concept-header-parse">parsing</a>
`<code title="http-access-control-expose-headers"><a href="#http-access-control-expose-headers">Access-Control-Expose-Headers</a></code>` in
<a href="#concept-internal-response" title="concept-internal-response">internal response</a>'s
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a>.
<p>An <dfn id="concept-filtered-response-opaque" title="concept-filtered-response-opaque">opaque filtered response</dfn> is a
<a href="#concept-filtered-response" title="concept-filtered-response">filtered response</a> whose
<a href="#concept-response-type" title="concept-response-type">type</a> is <i title="">opaque</i>,
<a href="#concept-response-status" title="concept-response-status">status</a> is <code title="">0</code>,
<a href="#concept-response-status-message" title="concept-response-status-message">status message</a> is the empty byte sequence,
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a> is an empty list, and
<a href="#concept-response-body" title="concept-response-body">body</a> is null.
<p class="note no-backref">In other words, an
<a href="#concept-filtered-response-opaque" title="concept-filtered-response-opaque">opaque filtered response</a> is nearly
indistinguishable from a <a href="#concept-network-error" title="concept-network-error">network error</a>. When
introducing new APIs, do not use the
<a href="#concept-internal-response" title="concept-internal-response">internal response</a> as you will leak
information.
<h2 id="http-extensions"><span class="secno">3 </span>HTTP extensions</h2>
<h3 id="origin-header"><span class="secno">3.1 </span>`<code title="">Origin</code>` header</h3>
<p>The `<dfn id="http-origin" title="http-origin"><code>Origin</code></dfn>` request
<a href="#concept-header" title="concept-header">header</a> indicates where a
<a href="#concept-fetch" title="concept-fetch">fetch</a> originates from.
<p class="note no-backref">The `<code title="http-origin"><a href="#http-origin">Origin</a></code>` header is a version
of the `<code title="http-referer">Referer</code>` [sic] header that does not reveal a
<a class="external" href="http://url.spec.whatwg.org/#concept-url-path" title="concept-url-path">path</a>. It is used for
all <a href="#concept-http-fetch" title="concept-http-fetch">HTTP fetches</a> whose <i title="">CORS flag</i> is
set as well as those where <a href="#concept-request" title="concept-request">request</a>'s
<a href="#concept-request-method" title="concept-request-method">method</a> is `<code title="">POST</code>`. Due to
compatibility constraints it is not included in all
<a href="#concept-fetch" title="concept-fetch">fetches</a>.
<!-- Ian Hickson told me Adam Barth researched that -->
<p>Its <a href="#concept-header-value" title="concept-header-value">value</a> ABNF:
<pre>Origin = origin-or-null
origin-or-null = origin / %x6E.75.6C.6C ; "null", case-sensitive
origin = <a class="external" href="http://url.spec.whatwg.org/#concept-url-scheme" title="concept-url-scheme">scheme</a> "://" <a class="external" href="http://url.spec.whatwg.org/#concept-url-host" title="concept-url-host">host</a> [ ":" <a class="external" href="http://url.spec.whatwg.org/#concept-url-port" title="concept-url-port">port</a> ]</pre>
<p class="note no-backref">This supplants the `<code title="http-origin"><a href="#http-origin">Origin</a></code>`
<a href="#concept-header" title="concept-header">header</a>.
<a class="informative" href="#refsORIGIN">[ORIGIN]</a>
<h3 id="http-cors-protocol"><span class="secno">3.2 </span>CORS protocol</h3>
<p>To allow sharing resources cross-origin and allow for more versatile HTTP requests than
possible with HTML's <code class="external"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#the-form-element">form</a></code> element, the platform has
a <dfn id="cors-protocol">CORS protocol</dfn> layered on top of HTTP. It allows resources to declare they
can be shared with resources residing on a different
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#origin">origin</a>.
<p class="note">It needs to be an opt-in mechanism to prevent leaking data from resources
behind a firewall (intranets). Additionally, for credentialed HTTP requests it needs to be
opt-in to prevent leaking potentially-sensitive data.
<p>This section explains the <a href="#cors-protocol">CORS protocol</a> as it pertains to servers.
Requirements for user agents are part of the <a href="#concept-fetch" title="concept-fetch">fetch</a>
algorithm.
<h4 id="general"><span class="secno">3.2.1 </span>General</h4>
<p>The <a href="#cors-protocol">CORS protocol</a> consists of a set of headers that indicates whether a
particular resource can be shared cross-origin.
<p>For HTTP requests that are more involved than what is possible with HTML's
<code class="external"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#the-form-element">form</a></code> element, a <a href="#cors-preflight-fetch-0">CORS preflight fetch</a> is
performed, to ensure the resource understands the <a href="#cors-protocol">CORS protocol</a>.
<h4 id="http-requests"><span class="secno">3.2.2 </span>HTTP requests</h4>
<p>An HTTP request can be identified as pertaining in the <a href="#cors-protocol">CORS protocol</a> if it
includes an `<code title="http-origin"><a href="#http-origin">Origin</a></code>` header. This is named a
<dfn id="cors-request">CORS request</dfn>.
<p>An HTTP request can be identified as being a check to see if the
<a href="#cors-protocol">CORS protocol</a> is understood if it is a <a href="#cors-request">CORS request</a>, uses
`<code title="">OPTIONS</code>` as <a href="#concept-method" title="concept-method">method</a>, and includes
these <a href="#concept-header" title="concept-header">headers</a>:
<dl>
<dt>`<dfn id="http-access-control-request-method" title="http-access-control-request-method"><code>Access-Control-Request-Method</code></dfn>`
<dd><p>Indicates which <a href="#concept-method" title="concept-method">method</a> a future
<a href="#cors-request">CORS request</a> to the same resource might use.
<dt>`<dfn id="http-access-control-request-headers" title="http-access-control-request-headers"><code>Access-Control-Request-Headers</code></dfn>`
<dd><p>Indicates which <a href="#concept-header" title="concept-header">headers</a> a future
<a href="#cors-request">CORS request</a> to the same resource might use.
</dl>
<p>This is named a <dfn id="cors-preflight-request">CORS preflight request</dfn>.
<h4 id="http-responses"><span class="secno">3.2.3 </span>HTTP responses</h4>
<p>An HTTP response to a <a href="#cors-request">CORS request</a> can include the following
<a href="#concept-header" title="concept-header">headers</a>:
<dl>
<dt>`<dfn id="http-access-control-allow-origin" title="http-access-control-allow-origin"><code>Access-Control-Allow-Origin</code></dfn>`
<dd><p>Indicates whether a resource can be shared, via returning the literal
<a href="#concept-header-value" title="concept-header-value">value</a> of the
<code title="http-origin"><a href="#http-origin">Origin</a></code> request <a href="#concept-header" title="concept-header">header</a>
(which can be `<code title="">null</code>`) or `<code title="">*</code>` in a response.
<dt>`<dfn id="http-access-control-allow-credentials" title="http-access-control-allow-credentials"><code>Access-Control-Allow-Credentials</code></dfn>`
<dd>
<p>Indicates whether a resource can be shared when
<a href="#concept-request" title="concept-request">request</a>'s
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a> is
<i title="">include</i>.
<p class="note">For a <a href="#cors-preflight-request">CORS preflight request</a>,
<a href="#concept-request" title="concept-request">request</a>'s
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a> is always
<i title="">omit</i>, but for any subsequent
<a href="#cors-request" title="CORS request">CORS requests</a> it might not be. Support therefore needs
to be indicated as part of the HTTP response to the <a href="#cors-preflight-request">CORS preflight request</a>
as well.
</dl>
<p>An HTTP response to a <a href="#cors-preflight-request">CORS preflight request</a> can include the following
<a href="#concept-header" title="concept-header">headers</a>:
<dl>
<dt>`<dfn id="http-access-control-allow-methods" title="http-access-control-allow-methods"><code>Access-Control-Allow-Methods</code></dfn>`
<dd>
<p>Indicates which <a href="#concept-method" title="concept-method">methods</a> are supported by the
resource for the purposes of the <a href="#cors-protocol">CORS protocol</a>.
<p class="note">The `<code title="">Allow</code>` <a href="#concept-header" title="concept-header">header</a> is
not relevant for the purposes of the <a href="#cors-protocol">CORS protocol</a>.
<dt>`<dfn id="http-access-control-allow-headers" title="http-access-control-allow-headers"><code>Access-Control-Allow-Headers</code></dfn>`
<dd><p>Indicates which <a href="#concept-header" title="concept-header">headers</a> are supported by the
resource for the purposes of the <a href="#cors-protocol">CORS protocol</a>.
<dt>`<dfn id="http-access-control-max-age" title="http-access-control-max-age"><code>Access-Control-Max-Age</code></dfn>`
<dd><p>Indicates how long the information provided by the
`<code title="http-access-control-allow-methods"><a href="#http-access-control-allow-methods">Access-Control-Allow-Methods</a></code>` and
`<code title="http-access-control-allow-headers"><a href="#http-access-control-allow-headers">Access-Control-Allow-Headers</a></code>`
<a href="#concept-header" title="concept-header">headers</a> can be cached.
</dl>
<p>An HTTP response to a <a href="#cors-request">CORS request</a> that is not a
<a href="#cors-preflight-request">CORS preflight request</a> can also include the following
<a href="#concept-header" title="concept-header">header</a>:
<dl>
<dt>`<dfn id="http-access-control-expose-headers" title="http-access-control-expose-headers"><code>Access-Control-Expose-Headers</code></dfn>`
<dd><p>Indicates which <a href="#concept-header" title="concept-header">headers</a> can be exposed as part
of the HTTP response, via listing their <a href="#concept-header-name" title="concept-header-name">names</a>.
</dl>
<h4 id="http-new-header-syntax"><span class="secno">3.2.4 </span>HTTP new header syntax</h4>
<p>ABNF for the <a href="#concept-header-value" title="concept-header-value">values</a> of the
<a href="#concept-header" title="concept-header">headers</a> used by the <a href="#cors-protocol">CORS protocol</a>: