This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
forked from whatwg/fetch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.bs
9201 lines (7033 loc) · 373 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
Shortname: fetch
Group: wintercg
Status: w3c/CG-DRAFT
Level: none
URL: https://fetch.spec.wintercg.org/
Repository: https://github.com/wintercg/fetch
Editor: Ethan Arrowood, Vercel http://vercel.com, [email protected]
Abstract: A fork of the WHATWG Fetch standard that defines requests, responses, and the process that binds them: fetching.
Markup Shorthands: css off
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>
<pre class=anchors>
urlPrefix:https://httpwg.org/specs/rfc5861.html#;type:dfn;spec:stale-while-revalidate
url:n-the-stale-while-revalidate-cache-control-extension;text:stale-while-revalidate lifetime
urlPrefix:https://httpwg.org/specs/rfc8941.html#;type:dfn;spec:rfc8941
url:rfc.section.2;text:structured field value
url:text-serialize;text:serializing structured fields
url:text-parse;text:parsing structured fields
url:;text:structured header
url:token;text:structured field token
urlPrefix:https://httpwg.org/specs/rfc9110.html#;type:dfn;spec:http
url:method.overview;text:method
url:fields.names;text:field-name
url:fields.values;text:field-value
url:rfc.section.9.2.1;text:unsafe
urlPrefix:https://httpwg.org/specs/rfc9111.html#;type:dfn;spec:http-caching
url:delta-seconds;text:delta-seconds
url:age.calculations;text:current age
url:calculating.freshness.lifetime;text:freshness lifetime
url:response.cacheability;text:Storing Responses in Caches
url:invalidation;text:Invalidating Stored Responses
url:validation.sent;text:Sending a Validation Request
url:constructing.responses.from.caches;text:Constructing Responses from Caches
url:freshening.responses;text:Freshening Stored Responses upon Validation
urlPrefix:https://httpwg.org/specs/rfc9112.html#;type:dfn;spec:http1
url:status.line;text:reason-phrase
url:https://w3c.github.io/resource-timing/#dfn-mark-resource-timing;text:mark resource timing;type:dfn;spec:resource-timing
urlPrefix:https://w3c.github.io/hr-time/#;spec:hr-time
type:dfn
url:dfn-coarsen-time;text:coarsen time
url:dfn-coarsened-shared-current-time;text:coarsened shared current time
url:dfn-unsafe-shared-current-time;text:unsafe shared current time
type:typedef;url:dom-domhighrestimestamp;text:DOMHighResTimeStamp
urlPrefix:https://tc39.es/ecma262/#;type:dfn;spec:ecma-262
url:realm;text:realm
url:sec-list-and-record-specification-type;text:Record
</pre>
<pre class=biblio>
{
"HTTP": {
"aliasOf": "RFC9110"
},
"HTTP-CACHING": {
"aliasOf": "RFC9111"
},
"HTTP1": {
"aliasOf": "RFC9112"
},
"HTTP3": {
"aliasOf": "RFC9114"
},
"HTTP3-DATAGRAM": {
"aliasOf": "RFC9297"
},
"REFERRER": {
"aliasOf": "referrer-policy"
},
"STALE-WHILE-REVALIDATE": {
"aliasOf": "RFC5861"
},
"SW": {
"aliasOf": "service-workers"
},
"HSTS": {
"aliasOf": "RFC6797"
},
"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."
},
"WEBTRANSPORT-HTTP3": {
"authors": ["V. Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3",
"publisher": "IETF",
"title": "WebTransport over HTTP/3"
},
"SVCB": {
"authors": ["Ben Schwartz", "Mike Bishop", "Erik Nygren"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https",
"publisher": "IETF",
"title": "Service binding and parameter specification via the DNS (DNS SVCB and HTTPS RRs)"
}
}
</pre>
<pre class=link-defaults>
spec:dom; type:dfn; text:element
spec:infra; type:dfn; text:implementation-defined
</pre>
<style>
/* WHATWG specs use the warning, XXX and domintro classes, which don't have a
* styling in the default W3C stylesheet. Here we give them a style similar to
* note, issue, etc. */
.warning, .XXX, .domintro {
padding: .5em;
border: .5em;
border-left-style: solid;
page-break-inside: avoid;
margin: 1em auto;
}
span.warning, span.XXX {
padding: .1em .5em .15em;
border-right-style: solid;
}
.warning > p:first-child, .XXX > p:first-child {
margin-top: 0;
}
.warning > p:last-child, .XXX > p:last-child {
margin-bottom: 0;
}
.warning, .XXX {
border-color: #990000;
background: #FFF0F0;
color: var(--text);
overflow: auto;
}
.warning::before {
content: "WARNING";
padding-right: 1em;
color: hsl(0, 70%, 30%);
}
.XXX {
color: hsl(0, 70%, 30%);
}
.domintro {
border-color: green;
background: #F0FFF0;
color: var(--text);
overflow: auto;
}
.domintro::before {
content: "For web developers (non-normative)";
display: block;
margin-bottom: .5em;
color: hsl(120, 70%, 30%);
}
@media (prefers-color-scheme: dark) {
.warning, .XXX, .domintro {
background: var(--borderedblock-bg);
}
.warning::before {
color: hsl(0, 70%, 70%);
}
.XXX {
color: hsl(0, 70%, 70%);
}
.domintro::before {
color: hsl(120, 70%, 70%);
}
}
</style>
<h2 id=wintercg-fork class="no-num short">About this fork</h2>
<p>This specification is a fork of the WHATWG Fetch spec [[FETCH]], made as part of the
<a href="https://wintercg.org">WinterCG</a> effort, to make it more suitable for server-side
JavaScript runtimes to implement.
<p>The goal of this fork on a short to medium term is to agree on the behavior of fetching in
server-side runtimes, and on the long term to upstream those changes into the WHATWG specification.
<p>The changes from the WHATWG spec so far are:
<ul>
<li><p>Added [[#conformance-classes]] to describe the various types of runtimes implementing this
fork.
<li><p>Made the <a>forbidden request-header</a> and <a>forbidden response-header name</a>
definitions dependent on whether the user agent <a>supports CORS</a> and
<a lt="support cookies">cookies</a>. This affects the headers of <a>basic filtered responses</a>,
as well as <a for=Headers lt=validate>validation</a> in {{Headers}} objects. The behavior for web
browsers doesn't change.
</ul>
<p class=XXX>Please update this list as new changes are added.
<p>This spec is still a work in progress, and some things we hope to specify in the future are:
<ul>
<li><p>Remove CORS restrictions for runtimes with no concept of origins.
<li><p>Specify how relative URLs resolve in {{fetch}} and the {{Request}} constructor for runtimes
without a concept of <a>API base URL</a>.
<li><p>Full-duplex request streaming (see
<a href="https://github.com/whatwg/fetch/issues/1254">WHATWG issue #1254</a>). Although this is not
specific to server-side runtimes, it's unlikely for browsers to implement it anytime soon.
<li><p>Specify how {{Request}} and {{Response}} behave in (runtime-specific) HTTP server APIs. Do
they behave as they do in <a for="/">service workers</a>?
<li><p>Etc.
</ul>
<h2 id=goals class="no-num short">Goals</h2>
<p>The goal is to unify fetching across the web platform and provide consistent handling of
everything that involves, including:
<ul class=brief>
<li>URL schemes
<li>Redirects
<li>Cross-origin semantics
<li>CSP [[!CSP]]
<li>Fetch Metadata [[!FETCH-METADATA]]
<li>Service workers [[!SW]]
<li>Mixed Content [[!MIX]]
<li>Upgrade Insecure Requests [[!UPGRADE-INSECURE-REQUESTS]]
<li>`<code>Referer</code>` [[!REFERRER]]
</ul>
<p>To do so it also supersedes the HTTP `<a http-header><code>Origin</code></a>` header semantics
originally defined in <cite>The Web Origin Concept</cite>. [[ORIGIN]]
<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 method><code>fetch()</code></a> JavaScript API, which
exposes most of the networking functionality at a fairly low level of abstraction.
<h2 id=conformance-classes>Conformance classes</h2>
<p>This specification applies to any <a spec="infra">user agent</a> that chooses to implement it.
However, different types of user agent have different needs in regards to fetching, and so this
specification defines different categories among which implementers might fall.
<p>A user agent implementing this specification:
<dl>
<dt><dfn>supports CORS</dfn></dt>
<dd>if it has a concept of an <a for=/>origin</a> which the current ECMAScript execution context
runs in, and which defines a security boundary with code and data from other origins. [[!HTML]]
[[ORIGIN]]
<dt><dfn>supports cookies</dfn></dt>
<dd>if it supports the user agent requirements of [[!COOKIES]]. For the purposes of this
specification, user agents which don't <a>support cookies</a> must act as if they were configured
to block cookies for all requests and responses (see
<a href=https://httpwg.org/specs/rfc6265.html#privacy-considerations>section 7</a> of
[[!COOKIES]]).
</dl>
<p class=note>Web browsers support both CORS and cookies.
<h2 id=infrastructure>Infrastructure</h2>
<p>This specification depends on the Infra Standard. [[!INFRA]]
<p>This specification uses terminology from <cite>ABNF</cite>, <cite>Encoding</cite>,
<cite>HTML</cite>, <cite>HTTP</cite>, <cite>MIME Sniffing</cite>, <cite>Streams</cite>,
<cite>URL</cite>, <cite>Web IDL</cite>, and <cite>WebSockets</cite>.
[[!ABNF]]
[[!ENCODING]]
[[!HTML]]
[[!HTTP]]
[[!MIMESNIFF]]
[[!STREAMS]]
[[!URL]]
[[!WEBIDL]]
[[!WEBSOCKETS]]
<p><dfn>ABNF</dfn> means ABNF as augmented by HTTP (in particular the addition of <code>#</code>)
and RFC 7405. [[!RFC7405]]
<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]]
<hr>
<p>A <dfn>fetch params</dfn> is a <a for=/>struct</a> used as a bookkeeping detail by the
<a for=/>fetch</a> algorithm. It has the following <a for=struct>items</a>:
<dl>
<dt><dfn for="fetch params">request</dfn>
<dd>A <a for=/>request</a>.
<dt><dfn for="fetch params" id=fetch-params-process-request-body>process request body chunk length</dfn>
(default null)
<dt><dfn for="fetch params">process request end-of-body</dfn> (default null)
<dt><dfn for="fetch params">process early hints response</dfn> (default null)
<dt><dfn for="fetch params">process response</dfn> (default null)
<dt><dfn for="fetch params">process response end-of-body</dfn> (default null)
<dt><dfn for="fetch params">process response consume body</dfn> (default null)
<dd>Null or an algorithm.
<dt><dfn for="fetch params">task destination</dfn> (default null)
<dd>Null, a <a for=/>global object</a>, or a <a for=/>parallel queue</a>.
<dt><dfn for="fetch params">cross-origin isolated capability</dfn> (default false)
<dd>A boolean.
<dt><dfn for="fetch params">controller</dfn> (default a new <a for=/>fetch controller</a>)
<dd>A <a for=/>fetch controller</a>.
<dt><dfn for="fetch params">timing info</dfn>
<dd>A <a for=/>fetch timing info</a>.
<dt><dfn export for="fetch params">preloaded response candidate</dfn> (default null)
<dd>Null, "<code>pending</code>", or a <a for=/>response</a>.
</dl>
<p>A <dfn export>fetch controller</dfn> is a <a for=/>struct</a> used to enable callers of
<a for=/>fetch</a> to perform certain operations on it after it has started. It has the following
<a for=struct>items</a>:
<dl>
<dt><dfn for="fetch controller" export>state</dfn> (default "<code>ongoing</code>")
<dd>"<code>ongoing</code>", "<code>terminated</code>", or "<code>aborted</code>"
<dt><dfn for="fetch controller">full timing info</dfn> (default null)
<dd>Null or a <a for=/>fetch timing info</a>.
<dt><dfn for="fetch controller">report timing steps</dfn> (default null)
<dd>Null or an algorithm accepting a <a for=/>global object</a>.
<dt><dfn for="fetch controller">serialized abort reason</dfn> (default null)
<dd>Null or a <a>Record</a> (result of [$StructuredSerialize$]).
<dt><dfn for="fetch controller">next manual redirect steps</dfn> (default null)
<dd>Null or an algorithm accepting nothing.
</dl>
<div algorithm>
<p>To <dfn export for="fetch controller" id="finalize-and-report-timing">report timing</dfn> for a
<a>fetch controller</a> <var>controller</var> given a <a for=/>global object</a> <var>global</var>:
<ol>
<li><p><a for=/>Assert</a>: <var>controller</var>'s
<a for="fetch controller">report timing steps</a> is non-null.
<li><p>Call <var>controller</var>'s <a for="fetch controller">report timing steps</a> with
<var>global</var>.
</ol>
</div>
<div algorithm>
<p>To <dfn export for="fetch controller">process the next manual redirect</dfn> for a
<a>fetch controller</a> <var>controller</var>:
<ol>
<li><p><a for=/>Assert</a>: <var>controller</var>'s
<a for="fetch controller">next manual redirect steps</a> is non-null.
<li><p>Call <var>controller</var>'s <a for="fetch controller">next manual redirect steps</a>.
</ol>
</div>
<div algorithm>
<p>To
<dfn export for="fetch controller" id="extract-full-timing-info">extract full timing info</dfn>
given a <a>fetch controller</a> <var>controller</var>:
<ol>
<li><p><a for=/>Assert</a>: <var>controller</var>'s <a for="fetch controller">full timing info</a>
is non-null.
<li><p>Return <var>controller</var>'s <a for="fetch controller">full timing info</a>.
</ol>
</div>
<div algorithm>
<p>To <dfn export for="fetch controller">abort</dfn> a <a for=/>fetch controller</a>
<var>controller</var> with an optional <var>error</var>:
<ol>
<li><p>Set <var>controller</var>'s <a for="fetch controller">state</a> to "<code>aborted</code>".
<li><p>Let <var>fallbackError</var> be an "{{AbortError}}" {{DOMException}}.
<li><p>Set <var>error</var> to <var>fallbackError</var> if it is not given.
<li><p>Let <var>serializedError</var> be [$StructuredSerialize$](<var>error</var>).
If that threw an exception, catch it, and let <var>serializedError</var> be
[$StructuredSerialize$](<var>fallbackError</var>).
<li><p>Set <var>controller</var>'s <a for="fetch controller">serialized abort reason</a> to
<var>serializedError</var>.
</ol>
</div>
<div algorithm>
<p>To <dfn export>deserialize a serialized abort reason</dfn>, given null or a <a>Record</a>
<var>abortReason</var> and a <a>realm</a> <var>realm</var>:
<ol>
<li><p>Let <var>fallbackError</var> be an "{{AbortError}}" {{DOMException}}.
<li><p>Let <var>deserializedError</var> be <var>fallbackError</var>.
<li><p>If <var>abortReason</var> is non-null, then set <var>deserializedError</var> to
[$StructuredDeserialize$](<var>abortReason</var>, <var>realm</var>). If that threw an exception or
returned undefined, then set <var>deserializedError</var> to <var>fallbackError</var>.
<li><p>Return <var>deserializedError</var>.
</ol>
</div>
<div algorithm>
<p>To <dfn export for="fetch controller">terminate</dfn> a <a for=/>fetch controller</a>
<var>controller</var>, set <var>controller</var>'s <a for="fetch controller">state</a> to
"<code>terminated</code>".
</div>
<p>A <a for=/>fetch params</a> <var>fetchParams</var> is <dfn for="fetch params">aborted</dfn> if
its <a for="fetch params">controller</a>'s <a for="fetch controller">state</a> is
"<code>aborted</code>".
<p>A <a for=/>fetch params</a> <var>fetchParams</var> is <dfn for="fetch params">canceled</dfn> if
its <a for="fetch params">controller</a>'s <a for="fetch controller">state</a> is
"<code>aborted</code>" or "<code>terminated</code>".
<p>A <dfn export>fetch timing info</dfn> is a <a for=/>struct</a> used to maintain timing
information needed by <cite>Resource Timing</cite> and <cite>Navigation Timing</cite>. It has the
following <a for=struct>items</a>: [[RESOURCE-TIMING]] [[NAVIGATION-TIMING]]
<dl>
<dt><dfn export for="fetch timing info">start time</dfn> (default 0)
<dt><dfn export for="fetch timing info">redirect start time</dfn> (default 0)
<dt><dfn export for="fetch timing info">redirect end time</dfn> (default 0)
<dt><dfn export for="fetch timing info">post-redirect start time</dfn> (default 0)
<dt><dfn export for="fetch timing info">final service worker start time</dfn> (default 0)
<dt><dfn export for="fetch timing info">final network-request start time</dfn> (default 0)
<dt><dfn export for="fetch timing info">final network-response start time</dfn> (default 0)
<dt><dfn export for="fetch timing info">end time</dfn> (default 0)
<dd>A {{DOMHighResTimeStamp}}.
<dt><dfn export for="fetch timing info">final connection timing info</dfn> (default null)
<dd>Null or a <a for=/>connection timing info</a>.
<dt><dfn export for="fetch timing info">server-timing headers</dfn> (default « »)
<dd>A <a for=/>list</a> of strings.
<dt><dfn export for="fetch timing info">render-blocking</dfn> (default false)
<dd>A boolean.
</dl>
<p>A <dfn export>response body info</dfn> is a <a for=/>struct</a> used to maintain
information needed by <cite>Resource Timing</cite> and <cite>Navigation Timing</cite>. It has the
following <a for=struct>items</a>: [[RESOURCE-TIMING]] [[NAVIGATION-TIMING]]
<dl>
<dt><dfn export for="response body info" id="fetch-timing-info-encoded-body-size">encoded
size</dfn> (default 0)
<dt><dfn export for="response body info" id="fetch-timing-info-decoded-body-size">decoded
size</dfn> (default 0)
<dd>A number.
</dl>
<div algorithm>
<p>To
<dfn export lt="create an opaque timing info|creating an opaque timing info">create an opaque timing info</dfn>,
given a <a for=/>fetch timing info</a> <var>timingInfo</var>, return a new
<a for=/>fetch timing info</a> whose <a for="fetch timing info">start time</a> and
<a for="fetch timing info">post-redirect start time</a> are <var>timingInfo</var>'s
<a for="fetch timing info">start time</a>.
</div>
<div algorithm>
<p>To <dfn>queue a fetch task</dfn>, given an algorithm <var>algorithm</var>, a
<a for=/>global object</a> or a <a for=/>parallel queue</a> <var>taskDestination</var>, run these
steps:
<ol>
<li><p>If <var>taskDestination</var> is a <a for=/>parallel queue</a>, then
<a lt="enqueue steps" for="parallel queue">enqueue</a> <var>algorithm</var> to
<var>taskDestination</var>.
<li><p>Otherwise, <a>queue a global task</a> on the <a>networking task source</a> with
<var>taskDestination</var> and <var>algorithm</var>.
</ol>
</div>
<hr>
<p>To <dfn>serialize an integer</dfn>, represent it as a string of the shortest possible decimal
number.
<p class=XXX>This will be replaced by a more descriptive algorithm in Infra. See
<a href="https://github.com/whatwg/infra/issues/201">infra/201</a>.
<h3 id=url>URL</h3>
<p>A <dfn export>local scheme</dfn> is "<code>about</code>", "<code>blob</code>", or
"<code>data</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 "<code>http</code>" or
"<code>https</code>".
<p>A <dfn export>fetch scheme</dfn> is "<code>about</code>", "<code>blob</code>",
"<code>data</code>", "<code>file</code>", or an <a>HTTP(S) scheme</a>.
<p class=note><a>HTTP(S) scheme</a> and <a>fetch scheme</a> are also used by <cite>HTML</cite>.
[[HTML]]
<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>An <dfn export>HTTP tab or space</dfn> is U+0009 TAB or U+0020 SPACE.
<p><dfn export>HTTP whitespace</dfn> is U+000A LF, U+000D CR, or an <a>HTTP tab or space</a>.
<p class=note><a>HTTP whitespace</a> is only useful for specific constructs that are reused outside
the context of HTTP headers (e.g., <a for=/>MIME types</a>). For HTTP header values, using
<a>HTTP tab or space</a> is preferred, and outside that context <a>ASCII whitespace</a> is
preferred. Unlike <a>ASCII whitespace</a> this excludes U+000C FF.
<p>An <dfn export>HTTP newline byte</dfn> is 0x0A (LF) or 0x0D (CR).
<p>An <dfn export>HTTP tab or space byte</dfn> is 0x09 (HT) or 0x20 (SP).
<p>An <dfn export>HTTP whitespace byte</dfn> is an <a>HTTP newline byte</a> or
<a>HTTP tab or space byte</a>.
<div algorithm>
<p>To
<dfn export lt="collect an HTTP quoted string|collecting an HTTP quoted string">collect an HTTP quoted string</dfn>
from a <a for=/>string</a> <var>input</var>, given a <a>position variable</a> <var>position</var>
and optionally an <var>extract-value flag</var>, run these steps:
<ol>
<li><p>Let <var>positionStart</var> be <var>position</var>.
<li><p>Let <var>value</var> be the empty string.
<li><p>Assert: the <a>code point</a> at <var>position</var> within <var>input</var> is U+0022 (").
<li><p>Advance <var>position</var> by 1.
<li>
<p>While true:
<ol>
<li><p>Append the result of <a>collecting a sequence of code points</a> that are not U+0022 (")
or U+005C (\) from <var>input</var>, given <var>position</var>, to <var>value</var>.
<li><p>If <var>position</var> is past the end of <var>input</var>, then
<a for=iteration>break</a>.
<li><p>Let <var>quoteOrBackslash</var> be the <a>code point</a> at <var>position</var> within
<var>input</var>.
<li><p>Advance <var>position</var> by 1.
<li>
<p>If <var>quoteOrBackslash</var> is U+005C (\), then:
<ol>
<li><p>If <var>position</var> is past the end of <var>input</var>, then append U+005C (\) to
<var>value</var> and <a for=iteration>break</a>.
<li><p>Append the <a>code point</a> at <var>position</var> within <var>input</var> to
<var>value</var>.
<li><p>Advance <var>position</var> by 1.
</ol>
<li>
<p>Otherwise:
<ol>
<li><p>Assert: <var>quoteOrBackslash</var> is U+0022 (").
<li><p><a for=iteration>Break</a>.
</ol>
</ol>
<li><p>If the <var>extract-value flag</var> is set, then return <var>value</var>.
<li><p>Return the <a for=/>code points</a> from <var>positionStart</var> to <var>position</var>,
inclusive, within <var>input</var>.
</ol>
<div class=example id=example-http-quoted-string>
<table>
<tr>
<th>Input
<th>Output
<th>Output with the <var>extract-value flag</var> set
<th>Final <a>position variable</a> value
<tr>
<td>"<code><mark>"\</mark></code>"
<td>"<code>"\</code>"
<td>"<code>\</code>"
<td>2
<tr>
<td>"<code><mark>"Hello"</mark> World</code>"
<td>"<code>"Hello"</code>"
<td>"<code>Hello</code>"
<td>7
<tr>
<td>"<code><mark>"Hello \\ World\""</mark></code>"
<td>"<code>"Hello \\ World\""</code>"
<td>"<code>Hello \ World"</code>"
<td>18
</table>
<p class=tablenote><small>The <a>position variable</a> always starts at 0 in these examples.</small>
</div>
</div>
<h4 id=methods>Methods</h4>
<p>A <dfn export id=concept-method>method</dfn> is a <a for=/>byte sequence</a> 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><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>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 class=note>HTTP generally refers to a header as a "field" or "header field". The web platform
uses the more colloquial term "header". [[HTTP]]
<!-- This will become more hairy if we add trailer support. -->
<p>A <dfn export id=concept-header-list>header list</dfn> is a <a for=/>list</a> of zero or more
<a for=/>headers</a>. It is initially « ».
<p class=note>A <a for=/>header list</a> is essentially a specialized multimap: an ordered list of
key-value pairs with potentially duplicate keys. Since headers other than `<code>Set-Cookie</code>`
are always combined when exposed to client-side JavaScript, implementations could choose a more
efficient representation, as long as they also support an associated data structure for
`<code>Set-Cookie</code>` headers.
<div algorithm>
<p>To
<dfn export for="header list" id=concept-header-list-get-structured-header>get a structured field value</dfn>
given a <a for=/>header name</a> <var>name</var> and a string <var>type</var> from a
<a for=/>header list</a> <var>list</var>, run these steps:
<ol>
<li><p>Assert: <var>type</var> is one of "<code>dictionary</code>", "<code>list</code>", or
"<code>item</code>".
<li><p>Let <var>value</var> be the result of <a for="header list">getting</a> <var>name</var> from
<var>list</var>.
<li><p>If <var>value</var> is null, then return null.
<li><p>Let <var>result</var> be the result of <a>parsing structured fields</a> with
<var ignore>input_string</var> set to <var>value</var> and <var ignore>header_type</var> set to
<var>type</var>.
<li><p>If parsing failed, then return null.
<li><p>Return <var>result</var>.
</ol>
<p class="note"><a>Get a structured field value</a> intentionally does not distinguish between a
<a for=/>header</a> not being present and its <a for=header>value</a> failing to parse as a
<a>structured field value</a>. This ensures uniform processing across the web platform.
</div>
<div algorithm>
<p>To
<dfn export for="header list" id=concept-header-list-set-structured-header>set a structured field value</dfn>
given a <a for=/>tuple</a> (<a for=/>header name</a> <var>name</var>, <a>structured field value</a>
<var>structuredValue</var>), in a <a for=/>header list</a> <var>list</var>, run these steps:
<ol>
<li><p>Let <var>serializedValue</var> be the result of executing the
<a>serializing structured fields</a> algorithm on <var>structuredValue</var>.
<li><p><a for="header list">Set</a> (<var>name</var>, <var>serializedValue</var>) in
<var>list</var>.
</ol>
<p class=note><a>Structured field values</a> are defined as objects which HTTP can (eventually)
serialize in interesting and efficient ways. For the moment, Fetch only supports
<a>header values</a> as <a for=/>byte sequences</a>, which means that these objects can be set in
<a for=/>header lists</a> only via serialization, and they can be obtained from
<a for=/>header lists</a> only by parsing. In the future the fact that they are objects might be
preserved end-to-end. [[!RFC8941]]
</div>
<hr>
<div algorithm>
<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> <a for=list>contains</a> a
<a for=/>header</a> whose <a for=header>name</a> is a <a>byte-case-insensitive</a> match for
<var>name</var>.
</div>
<div algorithm>
<p>To <dfn export for="header list" id=concept-header-list-get>get</dfn> a <a for=/>header name</a>
<var>name</var> from 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>Return 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.
</ol>
</div>
<div algorithm>
<p>To
<dfn export for="header list" lt="get, decode, and split|getting, decoding, and splitting" id=concept-header-list-get-decode-split>get, decode, and split</dfn>
a <a for=/>header name</a> <var>name</var> from <a for=/>header list</a> <var>list</var>, run these
steps:
<ol>
<li><p>Let <var>value</var> be the result of <a for="header list">getting</a> <var>name</var> from
<var>list</var>.
<li><p>If <var>value</var> is null, then return null.
<li><p>Return the result of <a for="header value">getting, decoding, and splitting</a>
<var>value</var>.
</ol>
</div>
<div class=example id=example-header-list-get-decode-split>
<p>This is how <a for="header list">get, decode, and split</a> functions in practice with
`<code>A</code>` as the <var>name</var> argument:
<table>
<tr>
<th>Headers (as on the network)
<th>Output
<tr>
<td>
<pre><code class=lang-http>
A: nosniff,
</code></pre>
<td rowspan=2>« "<code>nosniff</code>", "" »
<tr>
<td>
<pre><code class=lang-http>
A: nosniff
B: sniff
A:
</code></pre>
<tr>
<td>
<pre><code class=lang-http>A: text/html;", x/x</code></pre>
<td rowspan=2>« "<code>text/html;", x/x</code>" »
<tr>
<td>
<pre><code class=lang-http>
A: text/html;"
A: x/x
</code></pre>
<tr>
<td>
<pre><code class=lang-http>
A: x/x;test="hi",y/y
</code></pre>
<td rowspan=2>« "<code>x/x;test="hi"</code>", "<code>y/y</code>" »
<tr>
<td>
<pre><code class=lang-http>
A: x/x;test="hi"
C: **bingo**
A: y/y
</code></pre>
<tr>
<td>
<pre><code class=lang-http>
A: x / x,,,1
</code></pre>
<td rowspan=2>« "<code>x / x</code>", "", "", "<code>1</code>" »
<tr>
<td>
<pre><code class=lang-http>
A: x / x
A: ,
A: 1
</code></pre>
<tr>
<td>
<pre><code class=lang-http>
A: "1,2", 3
</code></pre>
<td rowspan=2>« "<code>"1,2"</code>", "<code>3</code>" »
<tr>
<td>
<pre><code class=lang-http>
A: "1,2"
D: 4
A: 3
</code></pre>
</table>
</div>
<div algorithm>
<p>To
<dfn for="header value" lt="get, decode, and split|getting, decoding, and splitting">get, decode, and split</dfn>
a <a for=/>header value</a> <var>value</var>, run these steps:
<ol>
<li><p>Let <var>input</var> be the result of <a>isomorphic decoding</a> <var>value</var>.
<li><p>Let <var>position</var> be a <a for=string>position variable</a> for <var>input</var>,
initially pointing at the start of <var>input</var>.
<li><p>Let <var>values</var> be a <a for=/>list</a> of <a for=/>strings</a>, initially empty.
<li><p>Let <var>temporaryValue</var> be the empty string.
<li>
<p>While <var>position</var> is not past the end of <var>input</var>:
<ol>
<li>
<p>Append the result of <a>collecting a sequence of code points</a> that are not U+0022 (") or
U+002C (,) from <var>input</var>, given <var>position</var>, to <var>temporaryValue</var>.
<p class=note>The result might be the empty string.
<li>
<p>If <var>position</var> is not past the end of <var>input</var>, then:
<ol>
<li>
<p>If the <a for=/>code point</a> at <var>position</var> within <var>input</var> is
U+0022 ("), then:
<ol>
<li><p>Append the result of <a>collecting an HTTP quoted string</a> from <var>input</var>,
given <var>position</var>, to <var>temporaryValue</var>.
<li>If <var>position</var> is not past the end of <var>input</var>, then
<a for=iteration>continue</a>.
</ol>
<li>
<p>Otherwise:
<ol>
<li><p>Assert: the <a for=/>code point</a> at <var>position</var> within <var>input</var> is
U+002C (,).
<li><p>Advance <var>position</var> by 1.
</ol>
</ol>
<li><p>Remove all <a>HTTP tab or space</a> from the start and end of <var>temporaryValue</var>.
<li><p><a for=list>Append</a> <var>temporaryValue</var> to <var>values</var>.
<li><p>Set <var>temporaryValue</var> to the empty string.
</ol>
<li><p>Return <var>values</var>.
</ol>
<p class=note>Except for blessed call sites, the algorithm directly above is not to be invoked
directly. Use <a for="header list">get, decode, and split</a> instead.
</div>
<div algorithm>
<p>To <dfn export for="header list" id=concept-header-list-append>append</dfn> a <a for=/>header</a>
(<var>name</var>, <var>value</var>) 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>This reuses the casing of the <a for=header>name</a> of the <a for=/>header</a>
already in <var>list</var>, if any. If there are multiple matched <a for=/>headers</a> their
<a for=header>names</a> will all be identical.
<li><p><a for=list>Append</a> (<var>name</var>, <var>value</var>) to <var>list</var>.
</ol>
</div>
<div algorithm>
<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>,
<a for=list>remove</a> 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>.
</div>
<div algorithm>
<p>To <dfn export for="header list" id=concept-header-list-set>set</dfn> a <a for=/>header</a>
(<var>name</var>, <var>value</var>) 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
<a for=list>remove</a> the others.
<li><p>Otherwise, <a for=list>append</a> (<var>name</var>, <var>value</var>) to <var>list</var>.
</ol>
</div>
<div algorithm>
<p>To <dfn export for="header list" id=concept-header-list-combine>combine</dfn> a
<a for=/>header</a> (<var>name</var>, <var>value</var>) 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, <a for=list>append</a> (<var>name</var>, <var>value</var>) to <var>list</var>.
</ol>
<p class=note><a for="header list">Combine</a> is used by {{XMLHttpRequest}} and the