forked from w3c/webtransport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.bs
1503 lines (1288 loc) · 59.8 KB
/
index.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: WebTransport
Shortname: webtransport
Level: none
Status: w3c/ED
Group: webtransport
ED: https://w3c.github.io/webtransport/
TR: https://www.w3.org/TR/webtransport/
Editor: Bernard Aboba, w3cid 65611, Microsoft Corporation
Editor: Victor Vasiliev, w3cid 113328,Google
Editor: Yutaka Hirano, w3cid 100504,Google
Former Editor: Peter Thatcher, Google
Former Editor: Robin Raymond, Optical Tone Ltd.
Abstract:
This document defines a set of ECMAScript APIs in WebIDL to allow data to be
sent and received between a browser and server, utilizing [[WEB-TRANSPORT-HTTP3]].
This specification is being developed in conjunction with a protocol
specification developed by the IETF WEBTRANS Working Group.
Repository: w3c/webtransport
Indent: 2
Markup Shorthands: markdown yes
Boilerplate: omit conformance
</pre>
<pre class="biblio">
{
"quic": {
"authors": ["Jana Iyengar", "Martin Thomson"],
"href": "https://tools.ietf.org/html/draft-ietf-quic-transport",
"title": "QUIC: A UDP-Based Multiplexed and Secure Transport",
"status": "Internet-Draft",
"publisher": "IETF"
},
"quic-datagram": {
"authors": ["Tommy Pauly", "Eric Kinnear", "David Schinazi"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-quic-datagram/",
"title": "An Unreliable Datagram Extension to QUIC",
"status": "Internet-Draft",
"publisher": "IETF"
},
"http3-datagram": {
"authors": ["David Schinazi", "Lucas Pardue"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-masque-h3-datagram",
"title": "Using QUIC Datagrams with HTTP/3",
"status": "Internet-Draft",
"publisher": "IETF"
},
"web-transport-overview": {
"authors": ["Victor Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-overview",
"title": "WebTransport Protocol Framework",
"status": "Internet-Draft",
"publisher": "IETF"
},
"web-transport-quic": {
"authors": ["Victor Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-vvv-webtransport-quic",
"title": "WebTransport over QUIC",
"status": "Internet-Draft",
"publisher": "IETF"
},
"web-transport-http3": {
"authors": ["Victor Vasiliev"],
"href": "https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/",
"title": "WebTransport over HTTP/3",
"status": "Internet-Draft",
"publisher": "IETF"
}
}
</pre>
<pre class="link-defaults">
spec:streams; type:interface; text:ReadableStream
spec:html; type:dfn; for:/; text:origin
spec:fetch; type:dfn; for:/; text:fetch
spec:url; type:dfn; text:scheme
spec:url; type:dfn; text:fragment
</pre>
<pre class="anchors">
urlPrefix: http://www.ecma-international.org/ecma-262/6.0/index.html; spec: ECMASCRIPT-6.0
type: dfn
text: fulfilled; url: sec-promise-objects
text: rejected; url: sec-promise-objects
text: pending; url: sec-promise-objects
text: resolved; url: sec-promise-objects
text: settled; url: sec-promise-objects
</pre>
# Introduction # {#introduction}
*This section is non-normative.*
This specification uses [[!WEB-TRANSPORT-HTTP3]] to send data to and receive
data from servers. It can be used like WebSockets but with support for multiple
streams, unidirectional streams, out-of-order delivery, and reliable as well as
unreliable transport.
Note: The API presented in this specification represents a preliminary proposal
based on work-in-progress within the IETF WEBTRANS WG. Since the [[!WEB-TRANSPORT-HTTP3]]
specification is a work-in-progress, both the protocol and API are likely to
change significantly going forward.
# Conformance # {#conformance}
As well as sections marked as non-normative, all authoring guidelines,
diagrams, examples, and notes in this specification are non-normative.
Everything else in this specification is normative.
The key words *MUST* and *SHOULD* are to be interpreted as described in
[[!RFC2119]].
This specification defines conformance criteria that apply to a single product:
the user agent that implements the interfaces that it contains.
Conformance requirements phrased as algorithms or specific steps may be
implemented in any manner, so long as the end result is equivalent. (In
particular, the algorithms defined in this specification are intended to be
easy to follow, and not intended to be performant.)
Implementations that use ECMAScript to implement the APIs defined in this
specification MUST implement them in a manner consistent with the ECMAScript
Bindings defined in the Web IDL specification [[!WEBIDL]], as this
specification uses that specification and terminology.
# Terminology # {#terminology}
The {{EventHandler}} interface, representing a callback used for event
handlers, and the {{ErrorEvent}} interface are defined in [[!HTML]].
The concepts [=queue a task=] and [=networking task source=] are defined in
[[!HTML]].
The terms [=event=], [=event handlers=] and [=event handler event types=] are
defined in [[!HTML]].
When referring to exceptions, the terms [=throw=] and [=create=] are defined in
[[!WEBIDL]].
The terms [=fulfilled=], [=rejected=], [=resolved=], [=pending=] and
[=settled=] used in the context of Promises are defined in [[!ECMASCRIPT-6.0]].
The terms {{ReadableStream}} and {{WritableStream}} are defined in
[[!WHATWG-STREAMS]].
# Protocol concepts # {#protocol-concepts}
A <dfn>WebTransport session</dfn> is a session of WebTransport over HTTP/3.
There may be multiple [=WebTransport session=]s on one [=connection=], when pooling is enabled.
[=WebTransport session=] has the following capabilities defined in [[!WEB-TRANSPORT-HTTP3]].
<table class="data" dfn-for="session">
<thead>
<tr>
<th>capability
<th>definition
</tr>
</thead>
<tbody>
<tr>
<td><dfn>send a datagram</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.4](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.4)
</tr>
<tr>
<td><dfn>receive a datagram</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.4](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.4)
</tr>
<tr>
<td><dfn>create an [=stream/outgoing=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.1)
</tr>
<tr>
<td><dfn>create a [=stream/bidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.2)
</tr>
<tr>
<td><dfn>receive an [=stream/incoming=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.1](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.1)
</tr>
<tr>
<td><dfn>receive a [=stream/bidirectional=] stream</dfn>
<td>[[!WEB-TRANSPORT-HTTP3]]
[section 4.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-4.3)
</tr>
</tbody>
</table>
To <dfn for=session>establish</dfn> a [=WebTransport session=], follow [[!WEB-TRANSPORT-HTTP3]]
[section 3.3](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-3.3).
To <dfn for=session>terminate</dfn> a [=WebTransport session=] |session| with an integer |code|,
follow [[!WEB-TRANSPORT-HTTP3]]
[section 5](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3/#section-5).
<dfn>WebTransport stream</dfn> is a concept for HTTP/3 stream on a [=WebTransport session=].
A [=WebTransport stream=] is one of <dfn for=stream>incoming</dfn>, <dfn for=stream>outgoing</dfn>
or <dfn for=stream>bidirectional</dfn>.
[=WebTransport stream=] has the following capabilities:
<table class="data" dfn-for="stream">
<thead>
<tr>
<th>capability
<th>definition
<th>incoming
<th>outgoing
<th>bidirectional
</tr>
</thead>
<tbody>
<tr>
<td><dfn>send</dfn> bytes (potentially with FIN)
<td>[[!QUIC]]
[section 2.2](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-2.2)
<td>No
<td>Yes
<td>Yes
</tr>
<tr>
<td><dfn>receive</dfn> bytes (potentially with FIN)
<td>[[!QUIC]]
[section 2.2](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-2.2)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>send STOP_SENDING</dfn>
<td>[[!QUIC]]
[section 3.5](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-3.5)
<td>Yes
<td>No
<td>Yes
</tr>
<tr>
<td><dfn>reset</dfn> a [=WebTransport stream=]
<td>[[!QUIC]]
[section 19.4](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport#section-19.4)
<td>No
<td>Yes
<td>Yes
</tr>
</tbody>
</table>
# `UnidirectionalStreamsTransport` Mixin # {#unidirectional-streams-transport}
A {{UnidirectionalStreamsTransport}} can send and receive unidirectional
streams. Data within a stream is delivered in order, but data between streams
may be delivered out of order. Data is generally sent reliably, but
retransmissions may be disabled or the stream may aborted to produce a form of
unreliability. All stream data is encrypted and congestion-controlled.
<pre class="idl">
interface mixin UnidirectionalStreamsTransport {
Promise<SendStream> createUnidirectionalStream(optional SendStreamParameters parameters = {});
/* a ReadableStream of ReceiveStream objects */
readonly attribute ReadableStream incomingUnidirectionalStreams;
};
</pre>
## Methods ## {#unidirectional-streams-transport-methods}
: <dfn for="UnidirectionalStreamsTransport" method>createUnidirectionalStream()</dfn>
:: Creates a {{SendStream}} object for an outgoing unidirectional stream. Note
that in some transports, the mere creation of a stream is not immediately
visible to the peer until it is used to send data.
When `createUnidirectionalStream()` method is called, the user agent MUST
run the following steps:
1. Let |transport| be the `UnidirectionalStreamsTransport` on which
`createUnidirectionalStream` is invoked.
1. If |transport|'s {{WebTransport/state}} is `"closed"` or `"failed"`,
immediately return a new [=rejected=] promise with a newly created
{{InvalidStateError}} and abort these steps.
1. Let |p| be a new promise.
1. Return |p| and continue the remaining steps [=in parallel=].
1. [=SendStream/Create=] a {{SendStream}} with |transport| and |p| when all
of the following conditions are met:
1. The |transport|'s {{WebTransport/state}} is `"connected"`.
1. Stream creation flow control is not being violated by exceeding the
max stream limit set by the remote endpoint, as specified in
[[!QUIC]].
1. |p| has not been [=settled=].
1. Queue a task to [=reject=] |p| with a newly created {{InvalidStateError}}
when all of the following conditions are met:
1. The |transport|'s state is `"closed"` or `"failed"`.
1. |p| has not been [=settled=].
: <dfn for="UnidirectionalStreamsTransport" attribute>incomingUnidirectionalStreams</dfn>
:: A {{ReadableStream}} of unidirectional streams, each represented by a
{{ReceiveStream}} object, that have been received from the remote host.
The getter steps for `incomingUnidirectionalStreams` are:
1. Let |transport| be the `UnidirectionalStreamsTransport` on which
the `incomingUnidirectionalStreams` getter is invoked.
1. Return |transport|'s [=[[ReceivedStreams]]=].
1. For each unidirectional stream received, create a corresponding
{{ReceiveStream}} and insert it into [=[[ReceivedStreams]]=]. As data
is received over the unidirectional stream, insert that data into the
corresponding `ReceiveStream` object. When the remote side closes or
aborts the stream, close or abort the corresponding `ReceiveStream`.
## Procedures ## {#unidirectional-streams-transport-procedures}
### Add SendStream to UnidirectionalStreamsTransport ### {#add-sendstream}
<div algorithm="create a SendStream">
To <dfn export for="SendStream" lt="create|creating">create</dfn> a
{{SendStream}} given a <var>transport</var> and a promise |p|, run the following
steps:
1. Reserve a unidirectional stream |association| in the underlying transport.
1. Queue a task to run the following sub-steps:
1. If |transport|'s state is `"closed"` or `"failed"`, abort these sub-steps.
1. Let |stream| be a newly created {{SendStream}} for |association|.
1. Add |stream| to |transport|'s [=[[OutgoingStreams]]=].
1. Resolve |p| with |stream|.
</div>
## SendStreamParameters Dictionary ## {#send-stream-parameters}
The <dfn dictionary>SendStreamParameters</dfn> dictionary includes information
relating to stream configuration.
<pre class="idl">
dictionary SendStreamParameters {
};
</pre>
# `DatagramDuplexStream` Interface # {#duplex-stream}
A <dfn interface>DatagramDuplexStream</dfn> is a generic duplex stream.
<pre class="idl">
[Exposed=(Window,Worker)]
interface DatagramDuplexStream {
readonly attribute ReadableStream readable;
readonly attribute WritableStream writable;
};
</pre>
## Internal slots ## {#datagramduplexstream-internal-slots}
A {{DatagramDuplexStream}} object has the following internal slots.
<table class="data" dfn-for="DatagramDuplexStream">
<thead>
<tr>
<th>Internal Slot
<th>Description (<em>non-normative</em>)
</tr>
</thead>
<tbody>
<tr>
<td><dfn>\[[Readable]]</dfn>
<td class="non-normative">A {{ReadableStream}} for incoming datagrams.
</tr>
<tr>
<td><dfn>\[[Writable]]</dfn>
<td class="non-normative">A {{WritableStream}} for outgoing datagrams.
</tr>
<tr>
<td><dfn>\[[IncomingDatagramsQueue]]</dfn>
<td class="non-normative">A queue of [=pairs=] of an incoming datagram and a timestamp.
</tr>
<tr>
<td><dfn>\[[IncomingDatagramsPullPromise]]</dfn>
<td class="non-normative">A promise set by [=pullDatagrams=], to wait for an incoming datagram.
</tr>
<tr>
<td><dfn>\[[IncomingDatagramsHighWaterMark]]</dfn>
<td class="non-normative">An integer representing the [=high water mark=] of the incoming
datagrams.
</tr>
<tr>
<td><dfn>\[[IncomingDatagramsExpirationDuration]]</dfn>
<td class="non-normative">A {{double}} value representing the expiration duration for incoming
datagrams (in milliseconds), or null.
</tr>
<tr>
<td><dfn>\[[OutgoingDatagramsQueue]]</dfn>
<td class="non-normative">A queue of tuples of an outgoing datagram, a timestamp and a promise
which is resolved when the datagram is sent or discarded.
</tr>
<tr>
<td><dfn>\[[OutgoingDatagramsHighWaterMark]]</dfn>
<td class="non-normative">An integer representing the [=high water mark=] of the outgoing
datagrams.
</tr>
<tr>
<td><dfn>\[[OutgoingDatagramsExpirationDuration]]</dfn>
<td class="non-normative">A {{double}} value representing the expiration duration for outgoing
datagrams (in milliseconds), or null.
</tr>
</tbody>
</table>
To <dfn export for="DatagramDuplexStream" lt="create|creating">create</dfn> a
{{DatagramDuplexStream}} given a
<dfn export for="DatagramDuplexStream/create"><var>readable</var></dfn>, and
a <dfn export for="DatagramDuplexStream/create"><var>writable</var></dfn>,
perform the following steps.
1. Let |stream| be a [=new=] {{DatagramDuplexStream}}, with:
: [=[[Readable]]=]
:: |readable|
: [=[[Writable]]=]
:: |writable|
: [=[[IncomingDatagramsQueue]]=]
:: an empty queue
: [=[[IncomingDatagramsPullPromise]]=]
:: null
: [=[[IncomingDatagramsHighWaterMark]]=]
:: an [=implementation-defined=] integer
: [=[[IncomingDatagramsExpirationDuration]]=]
:: null
: [=[[OutgoingDatagramsQueue]]=]
:: an empty queue
: [=[[OutgoingDatagramsHighWaterMark]]=]
:: an [=implementation-defined=] integer
<div class="note">
<p>This implementation-defined value should be tuned to ensure decent throughput, without
jeopardizing the timeliness of transmitted data.</p>
</div>
: [=[[OutgoingDatagramsExpirationDuration]]=]
:: null
1. Return |stream|.
## Attributes ## {#datagram-duplex-stream-attributes}
: <dfn for="DatagramDuplexStream" attribute>readable</dfn>
:: The getter steps are:
1. Return [=this=].`[[Readable]]`.
: <dfn for="DatagramDuplexStream" attribute>writable</dfn>
:: The getter steps are:
1. Return [=this=].`[[Writable]]`.
## Procedures ## {#datagram-duplex-stream-procedures}
To <dfn>pullDatagrams</dfn>, given a {{WebTransport}} object |transport|, run these steps:
1. Let |datagrams| be |transport|'s [=[[Datagrams]]=].
1. Assert: |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] is null.
1. Let |queue| be |datagrams|'s [=[[IncomingDatagramsQueue]]=].
1. If |queue| is empty, then:
1. Set |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] to a new promise.
1. Return |datagrams|'s [=[[IncomingDatagramsPullPromise]]=].
1. Let |bytes| and |timestamp| be the result of [=dequeuing=] |queue|.
1. Let |chunk| be a new {{Uint8Array}} object representing |bytes|.
1. [=ReadableStream/Enqueue=] |chunk| to |transport|'s [=[[Datagrams]]=]' s
[=DatagramDuplexStream/[[Readable]]=].
1. Return [=a promise resolved with=] undefined.
To <dfn>receiveDatagrams</dfn>, given a {{WebTransport}} object |transport|, run these steps:
1. Let |timestamp| be a timestamp representing now.
1. Let |queue| be |datagrams|'s [=[[IncomingDatagramsQueue]]=].
1. Let |duration| be |datagrams|'s [=[[IncomingDatagramsExpirationDuration]]=].
1. If |duration| is null, then set |duration| to an [=implementation-defined=] value.
1. Let |session| be |transport|'s [=[[Session]]=].
1. While there are [=session/receive a datagram|available incoming datagrams=] on |session|:
1. Let |datagram| be the result of [=session/receiving a datagram=] with |session|.
1. Let |timestamp| be a timestamp representing now.
1. Let |chunk| be a [=pair=] of |datagram| and |timestamp|.
1. [=Enqueue=] |chunk| to |queue|.
1. Let |toBeRemoved| be the length of |queue| minus |datagrams|'s
[=[[IncomingDatagramsHighWaterMark]]=].
1. If |toBeRemoved| is positive, repeat [=dequeuing=] |queue| |toBeRemoved| times.
1. While |queue| is not empty:
1. Let |bytes| and |timestamp| be |queue|'s first element.
1. If more than |duration| milliseconds have passed since |timestamp|, then [=dequeue=] |queue|.
1. Otherwise, [=break=] this loop.
1. If |queue| is not empty and |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] is non-null, then:
1. Let |bytes| and |timestamp| be the result of [=dequeuing=] |queue|.
1. Let |promise| be |datagrams|'s [=[[IncomingDatagramsPullPromise]]=].
1. Set |datagrams|'s [=[[IncomingDatagramsPullPromise]]=] to null.
1. [=Queue a global task=] on the [=network task source=] with |transport|'s
[=relevant global object=] and a task that runs the following steps:
1. Let |chunk| be a new {{Uint8Array}} object representing |bytes|.
1. [=ReadableStream/Enqueue=] |chunk| to |datagrams|'s [=DatagramDuplexStream/[[Readable]]=].
1. [=Resolve=] |promise| with undefined.
The user agent SHOULD run [=receiveDatagrams=] for any {{WebTransport}} object whose
[=[[State]]=] is `"connected"` as soon as reasonably possible whenever the algorithm can make
progress.
The <dfn>writeDatagrams</dfn> algorithm is given a |transport| as parameter and
|data| as input. It is defined by running the following steps:
1. Let |session| be |transport|'s [=[[Session]]=].
1. Let |timestamp| be a timestamp representing now.
1. If |data| is not a {{Uint8Array}} object, then return [=a promise rejected with=] a {{TypeError}}.
1. Let |promise| be a new promise.
1. Let |bytes| be a copy of bytes which |data| represents.
1. Let |chunk| be a tuple of |bytes|, |timestamp| and |promise|.
1. Let |datagrams| be |transport|'s [=[[Datagrams]]=].
1. Enqueue |chunk| to |datagrams|'s [=[[OutgoingDatagramsQueue]]=].
1. If the length of |datagrams|'s [=[[OutgoingDatagramsQueue]]=] is less than
|datagrams|'s [=[[OutgoingDatagramsHighWaterMark]]=], then [=resolve=] |promise| with undefined.
1. Return |promise|.
Note: The associated {{WritableStream}} calls [=writeDatagrams=] only when all the promises that
have been returned by [=writeDatagrams=] have been resolved. Hence the timestamp and the expiration
duration work well only when the web developer pays attention to
{{WritableStreamDefaultWriter/ready|WritableStreamDefaultWriter.ready}}.
To <dfn>sendDatagrams</dfn>, given a {{WebTransport}} object |transport|, run these steps:
1. Let |queue| be |datagrams|'s [=[[OutgoingDatagramsQueue]]=].
1. Let |duration| be |datagrams|'s [=[[OutgoingDatagramsExpirationDuration]]=].
1. If |duration| is null, then set |duration| to an [=implementation-defined=] value.
1. While |queue| is not empty:
1. Let |bytes|, |timestamp| and |promise| be |queue|'s first element.
1. If more than |duration| milliseconds have passed since |timestamp|, then:
1. [=Resolve=] |promise| with undefined.
1. Remove the first element from |queue|.
1. Otherwise, break this loop.
1. While |queue| is not empty:
1. Let |bytes|, |timestamp| and |promise| be |queue|'s first element.
1. If it is not possible to send |bytes| to the network immediately, then break this loop.
1. [=session/Send a datagram=], with |session| and |bytes|.
1. [=Resolve=] |promise| with undefined.
1. Remove the first element from |queue|.
The user agent SHOULD run [=sendDatagrams=] for any {{WebTransport}} object whose
[=[[State]]=] is `"connected"` as soon as reasonably possible whenever the algorithm can make
progress.
# `WebTransport` Interface # {#web-transport}
`WebTransport` provides an API to the HTTP/3 transport functionality
defined in [[!WEB-TRANSPORT-HTTP3]]. It implements {{UnidirectionalStreamsTransport}}
as well as stats and transport state information.
<pre class="idl">
[Exposed=(Window,Worker)]
interface WebTransport {
constructor(USVString url, optional WebTransportOptions options = {});
Promise<WebTransportStats> getStats();
readonly attribute WebTransportState state;
readonly attribute Promise<undefined> ready;
readonly attribute Promise<WebTransportCloseInfo> closed;
undefined close(optional WebTransportCloseInfo closeInfo = {});
attribute EventHandler onstatechange;
readonly attribute unsigned short maxDatagramSize;
readonly attribute DatagramDuplexStream datagrams;
Promise<BidirectionalStream> createBidirectionalStream();
/* a ReadableStream of BidirectionalStream objects */
readonly attribute ReadableStream incomingBidirectionalStreams;
};
WebTransport includes UnidirectionalStreamsTransport;
</pre>
## Internal slots ## {#webtransport-internal-slots}
A {{WebTransport}} object has the following internal slots.
<table class="data" dfn-for="WebTransport">
<thead>
<tr>
<th>Internal Slot
<th>Description (<em>non-normative</em>)
</tr>
</thead>
<tbody>
<tr>
<td><dfn>\[[OutgoingStreams]]</dfn>
<td class="non-normative">A sequence of {{SendStream}} objects.
</tr>
<tr>
<td><dfn>\[[ReceivedStreams]]</dfn>
<td class="non-normative">A {{ReadableStream}} consisting of {{ReceiveStream}} objects.
</tr>
<tr>
<td><dfn>\[[ReceivedBidirectionalStreams]]</dfn>
<td class="non-normative">A {{ReadableStream}} consisting of {{BidirectionalStream}} objects.
</tr>
<tr>
<td><dfn>\[[State]]</dfn>
<td class="non-normative">A {{WebTransportState}}.
</tr>
<tr>
<td><dfn>\[[Ready]]</dfn>
<td class="non-normative">A promise fulfilled when the associated [=WebTransport session=]
gets [=session/established=], or rejected if the [=session/establish|establishment process=]
failed.
</tr>
<tr>
<td><dfn>\[[Closed]]</dfn>
<td class="non-normative">A promise fulfilled when the associated {{WebTransport}} object is
closed gracefully, or rejected when it is closed abruptly or failed on initialization.
</tr>
<tr>
<td><dfn>\[[Datagrams]]</dfn>
<td class="non-normative">A {{DatagramDuplexStream}}.
</tr>
<tr>
<tr>
<td><dfn>\[[Session]]</dfn>
<td class="non-normative">A [=WebTransport session=] for this {{WebTransport}} object, or null.
</tr>
</table>
## Constructor ## {#webtransport-constructor}
When the {{WebTransport/constructor()}} constructor is invoked, the user
agent MUST run the following steps:
1. Let |parsedURL| be the [=URL record=] resulting from [=URL parser|parsing=]
{{WebTransport/constructor(url, options)/url}}.
1. If |parsedURL| is a failure, [=throw=] a {{SyntaxError}} exception.
1. If |parsedURL| [=scheme=] is not `https`, [=throw=] a {{SyntaxError}} exception.
1. If |parsedURL| [=fragment=] is not null, [=throw=] a {{SyntaxError}} exception.
1. Let |allowPooling| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/allowPooling}} if it exists, and false otherwise.
1. Let |dedicated| be the negation of |allowPooling|.
1. Let |serverCertificateFingerprints| be {{WebTransport/constructor(url, options)/options}}'s
{{WebTransportOptions/serverCertificateFingerprints}} if it exists, and null otherwise.
1. If |dedicated| is false and |serverCertificateFingerprints| is non-null, then [=throw=] a
{{TypeError}}.
1. Let |incomingDatagrams| be a [=new=] {{ReadableStream}}.
1. Let |outgoingDatagrams| be a [=new=] {{WritableStream}}.
1. Let |datagrams| be the result of [=DatagramDuplexStream/creating=] a
{{DatagramDuplexStream}}, its [=DatagramDuplexStream/create/readable=] set to
|incomingDatagrams| and its [=DatagramDuplexStream/create/writable=] set to |outgoingDatagrams|.
1. Let |transport| be a newly constructed {{WebTransport}} object, with:
: [=[[OutgoingStreams]]=]
:: empty
: [=[[ReceivedStreams]]=]
:: a new {{ReadableStream}}
: [=[[ReceivedBidirectionalStreams]]=]
:: a new {{ReadableStream}}
: [=[[State]]=]
:: `"connecting"`
: [=[[Ready]]=]
:: a new promise
: [=[[Closed]]=]
:: a new promise
: [=[[Datagrams]]=]
:: |datagrams|
: [=[[Session]]=]
:: null
1. Let |pullAlgorithm| be an action that runs [=pullDatagrams=] with |transport|.
1. Let |writeAlgorithm| be an action that runs [=writeDatagrams=] with |transport|.
1. [=ReadableStream/Set up=] |incomingDatagrams| with [=ReadableStream/set up/pullAlgorithm=]
set to |pullAlgorithm|, and [=ReadableStream/set up/highWaterMark=] set to 0.
1. [=WritableStream/Set up=] |outgoingDatagrams| with [=WritableStream/set up/writeAlgorithm=]
set to |writeAlgorithm|.
1. Let |promise| be the result of [=initialize WebTransport over HTTP|initializing WebTransport
over HTTP=], with |transport|, |parsedURL| and |dedicated|.
1. [=Upon fulfillment=] of |promise|, run these steps:
1. If |transport|'s [=[[State]]=] is not `"connecting"`, then abort these steps.
1. Set |transport|'s [=[[State]]=] to `"connected"`.
1. Resolve |transport|'s [=[[Ready]]=] with {{undefined}}.
1. [=Upon rejection=] of |promise| with |error|, run these steps:
1. Set |transport|'s [=[[State]]=] to `"failed"`.
1. Reject |transport|'s [=[[Ready]]=] with |error|.
1. Reject |transport|'s [=[[Closed]]=] with |error|.
1. Return |transport|.
<div algorithm="initialize WebTransport over HTTP">
To <dfn>initialize WebTransport over HTTP</dfn>, given a {{WebTransport}} object
<var>transport</var>, a [=URL record=] |url|, and a boolean |dedicated|, run these steps.
1. Let |promise| be a new promise.
1. Let |networkPartitionKey| be the result of [=determining the network partition key=] with
|transport|'s [=relevant settings object=].
1. Return |promise| and run the following steps [=in parallel=].
1. Let |connection| be the result of [=obtain a connection|obtaining a connection=] with
|networkPartitionKey|, |url|'s [=url/origin=], false, [=obtain a connection/http3Only=] set to
true, and [=obtain a connection/dedicated=] set to |dedicated|.
1. If |connection| is failure, then reject |promise| with a {{TypeError}} and abort these steps.
1. Wait for |connection| to receive the first SETTINGS frame, and let |settings| be a dictionary that
represents the SETTINGS frame.
1. If |settings| doesn't contain SETTINGS_ENABLE_WEBTRANPORT with a value of 1, or it doesn't
contain H3_DATAGRAM with a value of 1, then reject |promise| with a {{TypeError}} and abort
these steps.
1. [=session/Establish=] a [=WebTransport session=] on |connection|.
1. If the previous step fails, then reject |promise| with a {{TypeError}} and abort these steps.
1. Set |transport|'s [=[[Session]]=] to the established [=WebTransport session=].
1. Resolve |promise| with {{undefined}}.
</div>
## Attributes ## {#webtransport-attributes}
: <dfn for="WebTransport" attribute>state</dfn>
:: The current state of the transport. On getting, it MUST return [=this=]'s [=[[State]]=].
: <dfn for="WebTransport" attribute>ready</dfn>
:: On getting, it MUST return [=this=]'s [=[[Ready]]=].
: <dfn for="WebTransport" attribute>closed</dfn>
:: On getting, it MUST return [=this=]'s [=[[Closed]]=].
:: This promise MUST be [=resolved=] when the transport is closed; an
implementation SHOULD include error information in the `reason` and
`errorCode` fields of {{WebTransportCloseInfo}}.
: <dfn for="WebTransport" attribute>onstatechange</dfn>
:: This event handler, of event handler event type `statechange`, MUST be fired
any time the [=[[State]]=] changes, unless the state changes
due to calling {{WebTransport/close}}.
: <dfn for="WebTransport" attribute>maxDatagramSize</dfn>
:: The maximum size data that may be passed to
{{DatagramTransport/datagrams}}' {{DatagramDuplexStream/writable}}.
: <dfn for="WebTransport" attribute>datagrams</dfn>
:: A single duplex stream for sending and receiving datagrams over this session.
The getter steps for the `datagrams` attribute SHALL be:
1. Return [=this=]'s [=[[Datagrams]]=].
: <dfn for="WebTransport" attribute>incomingBidirectionalStreams</dfn>
:: Returns a {{ReadableStream}} of {{BidirectionalStream}}s that have been
received from the remote host.
The getter steps for the `incomingBidirectionalStreams` attribute SHALL be:
1. Return [=[[ReceivedBidirectionalStreams]]=].
1. For each bidirectional stream received, create a corresponding
{{BidirectionalStream}} and insert it into [=[[ReceivedBidirectionalStreams]]=].
As data is received over the bidirectional stream, insert that data into the
corresponding {{BidirectionalStream}}. When the remote side closes or aborts
the stream, close or abort the corresponding {{BidirectionalStream}}.
## Methods ## {#webtransport-methods}
: <dfn for="WebTransport" method>close(closeInfo)</dfn>
:: Terminates the [=WebTransport session=] associated with the WebTransport object.
When close is called, the user agent MUST run the following steps:
1. Let |transport| be [=this=].
1. If |transport|'s [=[[State]]=] is `"closed"` or `"failed"`,
then abort these steps.
1. Set |transport|'s [=[[State]]=] to `"closed"`.
1. Let |session| be |transport|'s [=[[Session]]=].
1. [=session/Terminate=] |session| with |closeInfo|.{{WebTransportCloseInfo/errorCode}}.
: <dfn for="WebTransport" method>getStats()</dfn>
:: Gathers stats for this {{WebTransport}}'s HTTP/3
connection and reports the result asynchronously.</p>
When close is called, the user agent MUST run the following steps:
1. Let |transport| be the WebTransport on which `getStats` is invoked.
1. Let |p| be a new promise.
1. If the URL scheme associated with |transport| is not `https`,
[=reject=] |p| with {{NotSupportedError}} and return |p|.
1. Return |p| and continue the following steps [=in parallel=].
1. Gather the stats from the underlying QUIC connection.
1. Once stats have been gathered, resolve |p| with the
{{WebTransportStats}} object, representing the gathered stats.
: <dfn for="WebTransport" method>createBidirectionalStream()</dfn>
:: Creates a {{BidirectionalStream}} object for an outgoing bidirectional
stream. Note that the mere creation of a stream is not immediately visible to the peer until
it is used to send data.
When `createBidirectionalStream` is called, the user agent MUST run the
following steps:
1. Let |transport| be [=this=].
1. If |transport|'s {{WebTransport/state}} is `"closed"` or `"failed"`,
immediately return a new [=rejected=] promise with a newly created
{{InvalidStateError}} and abort these steps.
1. Let |p| be a new promise.
1. Return |p| and continue the remaining steps [=in parallel=].
1. [=WebTransport/create a BidirectionalStream=] with |transport|
and |p| when all of the following conditions are met:
1. The |transport|'s {{WebTransport/state}} is `"connected"`.
1. Stream creation flow control is not being violated by exceeding the
max stream limit set by the remote endpoint, as specified in
[[!QUIC]].
1. |p| has not been [=settled=].
1. Queue a task to [=reject=] |p| with a newly created {{InvalidStateError}}
when all of the following conditions are met:
1. The |transport|'s state is `"closed"` or `"failed"`.
1. |p| has not been [=settled=].
<div algorithm="create a BidirectionalStream">
To <dfn for="WebTransport">create a {{BidirectionalStream}}</dfn>
given a <var>transport</var> and a promise |p|, run the following steps:
1. Reserve a bidirectional stream |association| in the underlying transport.
1. Queue a task to run the following sub-steps:
1. If |transport|'s state is `"closed"` or `"failed"`, abort these sub-steps.
1. Let |stream| be a newly created {{BidirectionalStream}} object for |association|.
1. Add |stream| to |transport|'s [=[[ReceivedBidirectionalStreams]]=].
1. Add |stream| to |transport|'s [=[[OutgoingStreams]]=].
1. Resolve |p| with |stream|.
</div>
## Configuration ## {#web-transport-configuration}
<pre class="idl">
dictionary WebTransportOptions {
boolean allowPooling;
sequence<RTCDtlsFingerprint> serverCertificateFingerprints;
};
</pre>
<dfn dictionary>WebTransportOptions</dfn> is a dictionary of parameters
that determine how WebTransport connection is established and used.
: <dfn for="WebTransportOptions" dict-member>allowPooling</dfn>
:: When set to true, the WebTransport connection can be pooled, that is, the network connection for
the WebTransport session can be shared with other HTTP/3 sessions.
: <dfn for="WebTransportOptions" dict-member>serverCertificateFingerprints</dfn>
:: This option is only supported for transports using dedicated connections.
For transport protocols that do not support this feature, having this
field non-empty SHALL result in a {{NotSupportedError}} exception being thrown.
:: If supported and non-empty, the user agent SHALL deem a server certificate
trusted if and only if it can successfully [=verify a certificate
fingerprint=] against {{WebTransportOptions/serverCertificateFingerprints}}
and satisfies [=custom certificate requirements=]. The user agent SHALL
ignore any fingerprint that uses an unknown {{RTCDtlsFingerprint/algorithm}}
or has a malformed {{RTCDtlsFingerprint/value}}. If empty, the user agent
SHALL use certificate verification procedures it would use for normal
[=fetch=] operations.
:: This cannot be used with {{WebTransportOptions/allowPooling}}.
<div algorithm="compute a certificate fingerprint">
To <dfn>compute a certificate fingerprint</dfn>, do the following:
1. Let |cert| be the input certificate, represented as a DER encoding of
Certificate message defined in [[!RFC5280]].
1. Compute the SHA-256 hash of |cert|. Format it as `fingerprint` BNF
rule described in Section 5 of [[!RFC8122]].
</div>
<div algorithm="verify a certificate fingerprint">
To <dfn>verify a certificate fingerprint</dfn>, do the following:
1. Let |fingerprints| be the input array of fingerprints.
1. Let |referenceFingerprint| be the [=compute a certificate fingerprint|computed
fingerprint=] of the input certificate.
1. For every fingerprint |fingerprint| in |fingerprints|:
1. If {{RTCDtlsFingerprint/algorithm}} of |fingerprint| is equal to "sha-256",
and {{RTCDtlsFingerprint/value}} of |fingerprint| is equal to
|referenceFingerprint|, the certificate is valid. Return true.
1. Return false.
</div>
The <dfn>custom certificate requirements</dfn> are as follows: the certificate
MUST be an X.509v3 certificate as defined in [[!RFC5280]], the current time
MUST be within the validity period of the certificate as defined in Section
4.1.2.5 of [[!RFC5280]] and the total length of the validity period MUST NOT
exceed two weeks.
Issue: Reconsider the time period above. We want it to be sufficiently large
that applications using this for ephemeral certificates can do so without
having to fight the clock skew, but small enough to discourage long-term use
without key rotation.
## `WebTransportState` Enum ## {#web-transport-state-enum}
<dfn enum>WebTransportState</dfn> indicates the state of the transport.
<pre class="idl">
enum WebTransportState {
"connecting",
"connected",
"closed",
"failed"
};
</pre>
: <dfn for="WebTransportState" enum-value>"connecting"</dfn>
:: The transport is in the process of negotiating a secure connection. Once a
secure connection is negotiated, incoming data can flow through.
: <dfn for="WebTransportState" enum-value>"connected"</dfn>
:: The transport has completed negotiation of a secure connection. Outgoing
data and media can now flow through.
: <dfn for="WebTransportState" enum-value>"closed"</dfn>
:: The transport has been closed intentionally via a call to
{{WebTransport/close()}} or receipt of a closing message from the remote
side. When the {{WebTransport}}'s [=[[State]]=]
transitions to `closed` the user agent MUST run the following steps:
1. Let |transport| be the {{WebTransport}}.
1. Close the {{ReadableStream}} in |transport|'s [=[[ReceivedStreams]]=].
1. Close the {{ReadableStream}} in |transport|'s
[=[[ReceivedBidirectionalStreams]]=].
1. For each {{SendStream}} in |transport|'s [=[[OutgoingStreams]]=]
run the following:
1. Let |stream| be the {{SendStream}}.
1. Remove the |stream| from the |transport|'s [=[[OutgoingStreams]]=].
: <dfn for="WebTransportState" enum-value>"failed"</dfn>
:: The transport has been closed as the result of an error (such as receipt of
an error alert). When the WebTransport's [=[[State]]=] transitions to
`failed` the user agent MUST run the following steps:
1. Close the {{ReadableStream}} in |transport|'s [=[[ReceivedStreams]]=].
1. Close the {{ReadableStream}} in |transport|'s
[=[[ReceivedBidirectionalStreams]]=].
1. For each {{SendStream}} in |transport|'s [=[[OutgoingStreams]]=]
run the following:
1. Remove the |stream| from the |transport|'s [=[[OutgoingStreams]]=].
## `WebTransportCloseInfo` Dictionary ## {#web-transport-close-info}
The <dfn dictionary>WebTransportCloseInfo</dfn> dictionary includes information
relating to the error code for closing a {{WebTransport}}. This
information is used to set the error code and reason for a CONNECTION_CLOSE
frame.
<pre class="idl">
dictionary WebTransportCloseInfo {
unsigned long long errorCode = 0;
DOMString reason = "";
};
</pre>
The dictionary SHALL have the following attributes:
: <dfn for="WebTransportCloseInfo" dict-member>errorCode</dfn>
:: The error code communicated to the peer.
: <dfn for="WebTransportCloseInfo" dict-member>reason</dfn>
:: The reason for closing the {{WebTransport}}.
## `WebTransportStats` Dictionary ## {#web-transport-stats}
The <dfn dictionary>WebTransportStats</dfn> dictionary includes information
on HTTP/3 connection stats.
Issue: Now that quic-transport has been removed, this section needs to be
revised. Some of those are safe to expose for HTTP/2 and HTTP/3 connections
(like min-RTT), while most would either result in information disclosure
or are impossible to define for pooled connections.
<pre class="idl">
dictionary WebTransportStats {
DOMHighResTimeStamp timestamp;
unsigned long long bytesSent;
unsigned long long packetsSent;
unsigned long numOutgoingStreamsCreated;
unsigned long numIncomingStreamsCreated;
unsigned long long bytesReceived;
unsigned long long packetsReceived;
DOMHighResTimeStamp minRtt;
unsigned long numReceivedDatagramsDropped;
};
</pre>
The dictionary SHALL have the following attributes:
: <dfn for="WebTransportStats" dict-member>timestamp</dfn>
:: The `timestamp` for when the stats are gathered, relative to the
UNIX epoch (Jan 1, 1970, UTC).
: <dfn for="WebTransportStats" dict-member>bytesSent</dfn>
:: The number of bytes sent on the QUIC connection, including retransmissions.
Does not include UDP or any other outer framing.
: <dfn for="WebTransportStats" dict-member>packetsSent</dfn>
:: The number of packets sent on the QUIC connection, including retransmissions.
: <dfn for="WebTransportStats" dict-member>numOutgoingStreamsCreated</dfn>
:: The number of outgoing QUIC streams created on the QUIC connection.
: <dfn for="WebTransportStats" dict-member>numIncomingStreamsCreated</dfn>
:: The number of incoming QUIC streams created on the QUIC connection.
: <dfn for="WebTransportStats" dict-member>bytesReceived</dfn>
:: The number of total bytes received on the QUIC connection, including
duplicate data for streams. Does not include UDP or any other outer framing.
: <dfn for="WebTransportStats" dict-member>packetsReceived</dfn>
:: The number of total packets received on the QUIC connection, including
packets that were not processable.
: <dfn for="WebTransportStats" dict-member>minRtt</dfn>
:: The minimum RTT observed on the entire connection.
: <dfn for="WebTransportStats" dict-member>numReceivedDatagramsDropped</dfn>
:: The number of datagrams that were dropped, due to too many datagrams buffered
between calls to {{DatagramTransport/datagrams}}' {{DatagramDuplexStream/readable}}.
# Interface `SendStream` # {#send-stream}
A <dfn interface>SendStream</dfn> is a {{WritableStream}} of {{Uint8Array}}
that can be written to, to transmit data to the remote host.
<pre class="idl">
[ Exposed=(Window,Worker) ]
interface SendStream : WritableStream /* of Uint8Array */ {
readonly attribute Promise<StreamAbortInfo> writingAborted;
undefined abortWriting(optional StreamAbortInfo abortInfo = {});
};
</pre>
## Overview ## {#outgoing-stream-overview}
The {{SendStream}} will be initialized by running the {{WritableStream}}
initialization steps.
## Attributes ## {#outgoing-stream-attributes}
: <dfn attribute for="SendStream">writingAborted</dfn>