-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathrfc9114_SUITE.erl
More file actions
2497 lines (2270 loc) · 91.5 KB
/
rfc9114_SUITE.erl
File metadata and controls
2497 lines (2270 loc) · 91.5 KB
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
%% Copyright (c) Loïc Hoguin <essen@ninenines.eu>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
%% copyright notice and this permission notice appear in all copies.
%%
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-module(rfc9114_SUITE).
-compile(export_all).
-compile(nowarn_export_all).
-import(ct_helper, [config/2]).
-import(ct_helper, [doc/1]).
-ifdef(COWBOY_QUICER).
-include_lib("quicer/include/quicer.hrl").
all() ->
[{group, h3}].
groups() ->
%% @todo Enable parallel tests but for this issues in the
%% QUIC accept loop need to be figured out (can't connect
%% concurrently somehow, no backlog?).
[{h3, [], ct_helper:all(?MODULE)}].
init_per_group(Name = h3, Config) ->
cowboy_test:init_http3(Name, #{
env => #{dispatch => cowboy_router:compile(init_routes(Config))}
}, Config).
end_per_group(Name, _) ->
cowboy_test:stop_group(Name).
init_routes(_) -> [
{"localhost", [
{"/", hello_h, []},
{"/echo/:key", echo_h, []}
]}
].
%% Starting HTTP/3 for "https" URIs.
alpn(Config) ->
doc("Successful ALPN negotiation. (RFC9114 3.1)"),
{ok, Conn} = quicer:connect("localhost", config(port, Config),
#{alpn => ["h3"], verify => none}, 5000),
{ok, <<"h3">>} = quicer:negotiated_protocol(Conn),
%% To make sure the connection is fully established we wait
%% to receive the SETTINGS frame on the control stream.
{ok, _ControlRef, _Settings} = do_wait_settings(Conn),
ok.
alpn_error(Config) ->
doc("Failed ALPN negotiation using the 'h2' token. (RFC9114 3.1)"),
{error, transport_down, #{status := alpn_neg_failure}}
= quicer:connect("localhost", config(port, Config),
#{alpn => ["h2"], verify => none}, 5000),
ok.
handshake_close_does_not_crash_acceptor(Config) ->
doc("A client that disconnects during handshake must not crash the QUIC acceptor. "
"(minimal repro for start_quic/3 handshake-close handling)"),
ok = gen_event:add_sup_handler(error_logger, error_forward_h, self()),
try
do_flush_error_events(),
do_trigger_handshake_closes(Config, 200),
Deadline = erlang:monotonic_time(millisecond) + 2000,
false = do_wait_for_start_quic_badmatch(Deadline),
%% Repro assertion: listener must still accept a fresh connection.
{ok, Conn1} = quicer:connect("localhost", config(port, Config),
#{alpn => ["h3"], verify => none}, 5000),
{ok, _ControlRef, _Settings} = do_wait_settings(Conn1),
ok = quicer:close_connection(Conn1),
ok
after
_ = catch gen_event:delete_handler(error_logger, error_forward_h, ok),
ok
end.
%% @todo 3.2. Connection Establishment
%% After the QUIC connection is established, a SETTINGS frame MUST be sent by each endpoint as the initial frame of their respective HTTP control stream.
%% @todo 3.3. Connection Reuse
%% Servers are encouraged to maintain open HTTP/3 connections for as long as
%possible but are permitted to terminate idle connections if necessary. When
%either endpoint chooses to close the HTTP/3 connection, the terminating
%endpoint SHOULD first send a GOAWAY frame (Section 5.2) so that both endpoints
%can reliably determine whether previously sent frames have been processed and
%gracefully complete or terminate any necessary remaining tasks.
%% Frame format.
req_stream(Config) ->
doc("Complete lifecycle of a request stream. (RFC9114 4.1)"),
{ok, Conn} = quicer:connect("localhost", config(port, Config),
#{alpn => ["h3"], verify => none}, 5000),
%% To make sure the connection is fully established we wait
%% to receive the SETTINGS frame on the control stream.
{ok, ControlRef, _Settings} = do_wait_settings(Conn),
%% Send a request on a request stream.
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"0">>}
], 0, cow_qpack:init(encoder)),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedRequest)),
EncodedRequest
], ?QUIC_SEND_FLAG_FIN),
%% Receive the response.
{ok, Data} = do_receive_data(StreamRef),
{HLenEnc, HLenBits} = do_guess_int_encoding(Data),
<<
1, %% HEADERS frame.
HLenEnc:2, HLen:HLenBits,
EncodedResponse:HLen/bytes,
Rest/bits
>> = Data,
{ok, DecodedResponse, _DecData, _DecSt}
= cow_qpack:decode_field_section(EncodedResponse, 0, cow_qpack:init(decoder)),
#{
<<":status">> := <<"200">>,
<<"content-length">> := BodyLen
} = maps:from_list(DecodedResponse),
{DLenEnc, DLenBits} = do_guess_int_encoding(Rest),
<<
0, %% DATA frame.
DLenEnc:2, DLen:DLenBits,
Body:DLen/bytes
>> = Rest,
<<"Hello world!">> = Body,
BodyLen = integer_to_binary(byte_size(Body)),
ok = do_wait_peer_send_shutdown(StreamRef),
ok = do_wait_stream_closed(StreamRef).
%% @todo Same test as above but with content-length unset?
req_stream_two_requests(Config) ->
doc("Receipt of multiple requests on a single stream must "
"be rejected with an H3_MESSAGE_ERROR stream error. "
"(RFC9114 4.1, RFC9114 4.1.2)"),
{ok, Conn} = quicer:connect("localhost", config(port, Config),
#{alpn => ["h3"], verify => none}, 5000),
%% To make sure the connection is fully established we wait
%% to receive the SETTINGS frame on the control stream.
{ok, ControlRef, _Settings} = do_wait_settings(Conn),
%% Send two requests on a request stream.
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedRequest1, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"0">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedRequest2, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"0">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedRequest1)),
EncodedRequest1,
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedRequest2)),
EncodedRequest2
]),
%% The stream should have been aborted.
#{reason := h3_message_error} = do_wait_stream_aborted(StreamRef),
ok.
headers_then_trailers(Config) ->
doc("Receipt of HEADERS followed by trailer HEADERS must be accepted. (RFC9114 4.1)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"0">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
headers_then_data_then_trailers(Config) ->
doc("Receipt of HEADERS followed by DATA followed by trailer HEADERS "
"must be accepted. (RFC9114 4.1)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
data_then_headers(Config) ->
doc("Receipt of DATA before HEADERS must be rejected "
"with an H3_FRAME_UNEXPECTED connection error. (RFC9114 4.1)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, _EncSt} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, _} = quicer:send(StreamRef, [
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>,
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders
], ?QUIC_SEND_FLAG_FIN),
%% The connection should have been closed.
#{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
ok.
headers_then_trailers_then_data(Config) ->
doc("Receipt of DATA after trailer HEADERS must be rejected "
"with an H3_FRAME_UNEXPECTED connection error. (RFC9114 4.1)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>
], ?QUIC_SEND_FLAG_FIN),
%% The connection should have been closed.
#{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
ok.
headers_then_data_then_trailers_then_data(Config) ->
doc("Receipt of DATA after trailer HEADERS must be rejected "
"with an H3_FRAME_UNEXPECTED connection error. (RFC9114 4.1)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>
], ?QUIC_SEND_FLAG_FIN),
%% The connection should have been closed.
#{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
ok.
headers_then_data_then_trailers_then_trailers(Config) ->
doc("Receipt of DATA after trailer HEADERS must be rejected "
"with an H3_FRAME_UNEXPECTED connection error. (RFC9114 4.1)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers1, _EncData2, EncSt1} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, EncodedTrailers2, _EncData3, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt1),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers1)),
EncodedTrailers1,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers2)),
EncodedTrailers2
], ?QUIC_SEND_FLAG_FIN),
%% The connection should have been closed.
#{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
ok.
unknown_then_headers(Config) ->
doc("Receipt of unknown frame followed by HEADERS "
"must be accepted. (RFC9114 4.1, RFC9114 9)"),
unknown_then_headers(Config, do_unknown_frame_type(),
rand:bytes(rand:uniform(4096))).
unknown_then_headers(Config, Type, Bytes) ->
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData, _EncSt} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"0">>}
], 0, cow_qpack:init(encoder)),
{ok, _} = quicer:send(StreamRef, [
cow_http3:encode_int(Type), %% Unknown frame.
cow_http3:encode_int(iolist_size(Bytes)),
Bytes,
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
headers_then_unknown(Config) ->
doc("Receipt of HEADERS followed by unknown frame "
"must be accepted. (RFC9114 4.1, RFC9114 9)"),
headers_then_unknown(Config, do_unknown_frame_type(),
rand:bytes(rand:uniform(4096))).
headers_then_unknown(Config, Type, Bytes) ->
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData, _EncSt} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"0">>}
], 0, cow_qpack:init(encoder)),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
cow_http3:encode_int(Type), %% Unknown frame.
cow_http3:encode_int(iolist_size(Bytes)),
Bytes
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
headers_then_data_then_unknown(Config) ->
doc("Receipt of HEADERS followed by DATA followed by unknown frame "
"must be accepted. (RFC9114 4.1, RFC9114 9)"),
headers_then_data_then_unknown(Config, do_unknown_frame_type(),
rand:bytes(rand:uniform(4096))).
headers_then_data_then_unknown(Config, Type, Bytes) ->
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData, _EncSt} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>,
cow_http3:encode_int(Type), %% Unknown frame.
cow_http3:encode_int(iolist_size(Bytes)),
Bytes
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
headers_then_trailers_then_unknown(Config) ->
doc("Receipt of HEADERS followed by trailer HEADERS followed by unknown frame "
"must be accepted. (RFC9114 4.1, RFC9114 9)"),
headers_then_data_then_unknown(Config, do_unknown_frame_type(),
rand:bytes(rand:uniform(4096))).
headers_then_trailers_then_unknown(Config, Type, Bytes) ->
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers,
cow_http3:encode_int(Type), %% Unknown frame.
cow_http3:encode_int(iolist_size(Bytes)),
Bytes
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
headers_then_data_then_unknown_then_trailers(Config) ->
doc("Receipt of HEADERS followed by DATA followed by "
"unknown frame followed by trailer HEADERS "
"must be accepted. (RFC9114 4.1, RFC9114 9)"),
headers_then_data_then_unknown_then_trailers(Config,
do_unknown_frame_type(), rand:bytes(rand:uniform(4096))).
headers_then_data_then_unknown_then_trailers(Config, Type, Bytes) ->
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>,
cow_http3:encode_int(Type), %% Unknown frame.
cow_http3:encode_int(iolist_size(Bytes)),
Bytes,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
headers_then_data_then_unknown_then_data(Config) ->
doc("Receipt of HEADERS followed by DATA followed by "
"unknown frame followed by DATA "
"must be accepted. (RFC9114 4.1, RFC9114 9)"),
headers_then_data_then_unknown_then_data(Config,
do_unknown_frame_type(), rand:bytes(rand:uniform(4096))).
headers_then_data_then_unknown_then_data(Config, Type, Bytes) ->
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData, _EncSt} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(6),
<<"Hello ">>,
cow_http3:encode_int(Type), %% Unknown frame.
cow_http3:encode_int(iolist_size(Bytes)),
Bytes,
<<0>>, %% DATA frame.
cow_http3:encode_int(7),
<<"server!">>
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
headers_then_data_then_trailers_then_unknown(Config) ->
doc("Receipt of HEADERS followed by DATA followed by "
"trailer HEADERS followed by unknown frame "
"must be accepted. (RFC9114 4.1, RFC9114 9)"),
headers_then_data_then_trailers_then_unknown(Config,
do_unknown_frame_type(), rand:bytes(rand:uniform(4096))).
headers_then_data_then_trailers_then_unknown(Config, Type, Bytes) ->
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"13">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(13),
<<"Hello server!">>,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers,
cow_http3:encode_int(Type), %% Unknown frame.
cow_http3:encode_int(iolist_size(Bytes)),
Bytes
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
do_unknown_frame_type() ->
Type = rand:uniform(4611686018427387904) - 1,
%% Retry if we get a value that's specified.
case lists:member(Type, [
16#0, 16#1, 16#3, 16#4, 16#5, 16#7, 16#d, %% HTTP/3 core frame types.
16#2, 16#6, 16#8, 16#9 %% HTTP/3 reserved frame types that must be rejected.
]) of
true -> do_unknown_frame_type();
false -> Type
end.
reserved_then_headers(Config) ->
doc("Receipt of reserved frame followed by HEADERS "
"must be accepted when the reserved frame type is "
"of the format 0x1f * N + 0x21. (RFC9114 4.1, RFC9114 7.2.8)"),
unknown_then_headers(Config, do_reserved_type(),
rand:bytes(rand:uniform(4096))).
headers_then_reserved(Config) ->
doc("Receipt of HEADERS followed by reserved frame "
"must be accepted when the reserved frame type is "
"of the format 0x1f * N + 0x21. (RFC9114 4.1, RFC9114 7.2.8)"),
headers_then_unknown(Config, do_reserved_type(),
rand:bytes(rand:uniform(4096))).
headers_then_data_then_reserved(Config) ->
doc("Receipt of HEADERS followed by DATA followed by reserved frame "
"must be accepted when the reserved frame type is "
"of the format 0x1f * N + 0x21. (RFC9114 4.1, RFC9114 7.2.8)"),
headers_then_data_then_unknown(Config, do_reserved_type(),
rand:bytes(rand:uniform(4096))).
headers_then_trailers_then_reserved(Config) ->
doc("Receipt of HEADERS followed by trailer HEADERS followed by reserved frame "
"must be accepted when the reserved frame type is "
"of the format 0x1f * N + 0x21. (RFC9114 4.1, RFC9114 7.2.8)"),
headers_then_trailers_then_unknown(Config, do_reserved_type(),
rand:bytes(rand:uniform(4096))).
headers_then_data_then_reserved_then_trailers(Config) ->
doc("Receipt of HEADERS followed by DATA followed by "
"reserved frame followed by trailer HEADERS "
"must be accepted when the reserved frame type is "
"of the format 0x1f * N + 0x21. (RFC9114 4.1, RFC9114 7.2.8)"),
headers_then_data_then_unknown_then_trailers(Config,
do_reserved_type(), rand:bytes(rand:uniform(4096))).
headers_then_data_then_reserved_then_data(Config) ->
doc("Receipt of HEADERS followed by DATA followed by "
"reserved frame followed by DATA "
"must be accepted when the reserved frame type is "
"of the format 0x1f * N + 0x21. (RFC9114 4.1, RFC9114 7.2.8)"),
headers_then_data_then_unknown_then_data(Config,
do_reserved_type(), rand:bytes(rand:uniform(4096))).
headers_then_data_then_trailers_then_reserved(Config) ->
doc("Receipt of HEADERS followed by DATA followed by "
"trailer HEADERS followed by reserved frame "
"must be accepted when the reserved frame type is "
"of the format 0x1f * N + 0x21. (RFC9114 4.1, RFC9114 7.2.8)"),
headers_then_data_then_trailers_then_unknown(Config,
do_reserved_type(), rand:bytes(rand:uniform(4096))).
reject_transfer_encoding_header_with_body(Config) ->
doc("Requests containing a transfer-encoding header must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.1, RFC9114 4.1.2, RFC9114 4.2)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, _EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"transfer-encoding">>, <<"chunked">>}
], 0, cow_qpack:init(encoder)),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(24),
<<"13\r\nHello server!\r\n0\r\n\r\n">>
]),
%% The stream should have been aborted.
#{reason := h3_message_error} = do_wait_stream_aborted(StreamRef),
ok.
%% 4. Expressing HTTP Semantics in HTTP/3
%% 4.1. HTTP Message Framing
%% An HTTP request/response exchange fully consumes a client-initiated
%bidirectional QUIC stream. After sending a request, a client MUST close the
%stream for sending. Unless using the CONNECT method (see Section 4.4), clients
%MUST NOT make stream closure dependent on receiving a response to their
%request. After sending a final response, the server MUST close the stream for
%sending. At this point, the QUIC stream is fully closed.
%% @todo What to do with clients that DON'T close the stream
%% for sending after the request is sent?
%% If a client-initiated stream terminates without enough of the HTTP message
%to provide a complete response, the server SHOULD abort its response stream
%with the error code H3_REQUEST_INCOMPLETE.
%% @todo difficult!!
%% When the server does not need to receive the remainder of the request, it
%MAY abort reading the request stream, send a complete response, and cleanly
%close the sending part of the stream. The error code H3_NO_ERROR SHOULD be
%used when requesting that the client stop sending on the request stream.
%% @todo read_body related; h2 has this behavior but there is no corresponding test
%% 4.1.1. Request Cancellation and Rejection
%% When possible, it is RECOMMENDED that servers send an HTTP response with an
%appropriate status code rather than cancelling a request it has already begun
%processing.
%% Implementations SHOULD cancel requests by abruptly terminating any
%directions of a stream that are still open. To do so, an implementation resets
%the sending parts of streams and aborts reading on the receiving parts of
%streams; see Section 2.4 of [QUIC-TRANSPORT].
%% When the server cancels a request without performing any application
%processing, the request is considered "rejected". The server SHOULD abort its
%response stream with the error code H3_REQUEST_REJECTED. In this context,
%"processed" means that some data from the stream was passed to some higher
%layer of software that might have taken some action as a result. The client
%can treat requests rejected by the server as though they had never been sent
%at all, thereby allowing them to be retried later.
%% Servers MUST NOT use the H3_REQUEST_REJECTED error code for requests that
%were partially or fully processed. When a server abandons a response after
%partial processing, it SHOULD abort its response stream with the error code
%H3_REQUEST_CANCELLED.
%% @todo
%% Client SHOULD use the error code H3_REQUEST_CANCELLED to cancel requests.
%Upon receipt of this error code, a server MAY abruptly terminate the response
%using the error code H3_REQUEST_REJECTED if no processing was performed.
%Clients MUST NOT use the H3_REQUEST_REJECTED error code, except when a server
%has requested closure of the request stream with this error code.
%% @todo
%4.1.2. Malformed Requests and Responses
%A malformed request or response is one that is an otherwise valid sequence of
%frames but is invalid due to:
%
%the presence of prohibited fields or pseudo-header fields,
%% @todo reject_response_pseudo_headers
%% @todo reject_unknown_pseudo_headers
%% @todo reject_pseudo_headers_in_trailers
%the absence of mandatory pseudo-header fields,
%invalid values for pseudo-header fields,
%pseudo-header fields after fields,
%% @todo reject_pseudo_headers_after_regular_headers
%an invalid sequence of HTTP messages,
%the inclusion of invalid characters in field names or values.
%
%A request or response that is defined as having content when it contains a
%Content-Length header field (Section 8.6 of [HTTP]) is malformed if the value
%of the Content-Length header field does not equal the sum of the DATA frame
%lengths received. A response that is defined as never having content, even
%when a Content-Length is present, can have a non-zero Content-Length header
%field even though no content is included in DATA frames.
%
%For malformed requests, a server MAY send an HTTP response indicating the
%error prior to closing or resetting the stream.
%% @todo All the malformed tests
headers_reject_uppercase_header_name(Config) ->
doc("Requests containing uppercase header names must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"I-AM-GIGANTIC">>, <<"How's the weather up there?">>}
).
%% 4.2. HTTP Fields
%% An endpoint MUST NOT generate an HTTP/3 field section containing
%connection-specific fields; any message containing connection-specific fields
%MUST be treated as malformed.
reject_connection_header(Config) ->
doc("Requests containing a connection header must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"connection">>, <<"close">>}
).
reject_keep_alive_header(Config) ->
doc("Requests containing a keep-alive header must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"keep-alive">>, <<"timeout=5, max=1000">>}
).
reject_proxy_authenticate_header(Config) ->
doc("Requests containing a proxy-authenticate header must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"proxy-authenticate">>, <<"Basic">>}
).
reject_proxy_authorization_header(Config) ->
doc("Requests containing a proxy-authorization header must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"proxy-authorization">>, <<"Basic YWxhZGRpbjpvcGVuc2VzYW1l">>}
).
reject_transfer_encoding_header(Config) ->
doc("Requests containing a transfer-encoding header must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"transfer-encoding">>, <<"chunked">>}
).
reject_upgrade_header(Config) ->
doc("Requests containing an upgrade header must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.5, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"upgrade">>, <<"websocket">>}
).
accept_te_header_value_trailers(Config) ->
doc("Requests containing a TE header with a value of \"trailers\" "
"must be accepted. (RFC9114 4.2)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"content-length">>, <<"0">>},
{<<"te">>, <<"trailers">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"content-type">>, <<"text/plain">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers
], ?QUIC_SEND_FLAG_FIN),
#{
headers := #{<<":status">> := <<"200">>},
body := <<"Hello world!">>
} = do_receive_response(StreamRef),
ok.
reject_te_header_other_values(Config) ->
doc("Requests containing a TE header with a value other than \"trailers\" must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.2, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<"te">>, <<"trailers, deflate;q=0.5">>}
).
%% @todo response_dont_send_header_in_connection
%% @todo response_dont_send_connection_header
%% @todo response_dont_send_keep_alive_header
%% @todo response_dont_send_proxy_connection_header
%% @todo response_dont_send_transfer_encoding_header
%% @todo response_dont_send_upgrade_header
%% 4.2.1. Field Compression
%% To allow for better compression efficiency, the Cookie header field
%([COOKIES]) MAY be split into separate field lines, each with one or more
%cookie-pairs, before compression. If a decompressed field section contains
%multiple cookie field lines, these MUST be concatenated into a single byte
%string using the two-byte delimiter of "; " (ASCII 0x3b, 0x20) before being
%passed into a context other than HTTP/2 or HTTP/3, such as an HTTP/1.1
%connection, or a generic HTTP server application.
%% 4.2.2. Header Size Constraints
%% An HTTP/3 implementation MAY impose a limit on the maximum size of the
%message header it will accept on an individual HTTP message. A server that
%receives a larger header section than it is willing to handle can send an HTTP
%431 (Request Header Fields Too Large) status code ([RFC6585]). The size of a
%field list is calculated based on the uncompressed size of fields, including
%the length of the name and value in bytes plus an overhead of 32 bytes for
%each field.
%% If an implementation wishes to advise its peer of this limit, it can be
%conveyed as a number of bytes in the SETTINGS_MAX_FIELD_SECTION_SIZE
%parameter.
reject_unknown_pseudo_headers(Config) ->
doc("Requests containing unknown pseudo-headers must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<":upgrade">>, <<"websocket">>}
).
reject_response_pseudo_headers(Config) ->
doc("Requests containing response pseudo-headers must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3, RFC9114 4.1.2)"),
do_reject_malformed_header(Config,
{<<":status">>, <<"200">>}
).
reject_pseudo_headers_in_trailers(Config) ->
doc("Requests containing pseudo-headers in trailers must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3, RFC9114 4.1.2)"),
#{conn := Conn} = do_connect(Config),
{ok, StreamRef} = quicer:start_stream(Conn, #{}),
{ok, EncodedHeaders, _EncData1, EncSt0} = cow_qpack:encode_field_section([
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>},
{<<"trailer">>, <<"x-checksum">>}
], 0, cow_qpack:init(encoder)),
{ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
{<<"x-checksum">>, <<"md5:4cc909a007407f3706399b6496babec3">>},
{<<":path">>, <<"/">>}
], 0, EncSt0),
{ok, _} = quicer:send(StreamRef, [
<<1>>, %% HEADERS frame.
cow_http3:encode_int(iolist_size(EncodedHeaders)),
EncodedHeaders,
<<0>>, %% DATA frame.
cow_http3:encode_int(10000),
<<0:10000/unit:8>>,
<<1>>, %% HEADERS frame for trailers.
cow_http3:encode_int(iolist_size(EncodedTrailers)),
EncodedTrailers
]),
%% The stream should have been aborted.
#{reason := h3_message_error} = do_wait_stream_aborted(StreamRef),
ok.
reject_pseudo_headers_after_regular_headers(Config) ->
doc("Requests containing pseudo-headers after regular headers must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3, RFC9114 4.1.2)"),
do_reject_malformed_headers(Config, [
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost">>},
{<<"content-length">>, <<"0">>},
{<<":path">>, <<"/">>}
]).
reject_userinfo(Config) ->
doc("An authority containing a userinfo component must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3.1, RFC9114 4.1.2)"),
do_reject_malformed_headers(Config, [
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"http">>},
{<<":authority">>, <<"user@localhost">>},
{<<":path">>, <<"/">>}
]).
%% To ensure that the HTTP/1.1 request line can be reproduced accurately, this
%% pseudo-header field (:authority) MUST be omitted when translating from an
%% HTTP/1.1 request that has a request target in a method-specific form;
%% see Section 7.1 of [HTTP].
reject_empty_path(Config) ->
doc("A request containing an empty path component must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3.1, RFC9114 4.1.2)"),
do_reject_malformed_headers(Config, [
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"http">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<>>}
]).
reject_missing_pseudo_header_method(Config) ->
doc("A request without a method component must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3.1, RFC9114 4.1.2)"),
do_reject_malformed_headers(Config, [
{<<":scheme">>, <<"http">>},
{<<":authority">>, <<"localhost">>},
{<<":path">>, <<"/">>}
]).
reject_many_pseudo_header_method(Config) ->
doc("A request containing more than one method component must be rejected "
"with an H3_MESSAGE_ERROR stream error. (RFC9114 4.3.1, RFC9114 4.1.2)"),
do_reject_malformed_headers(Config, [
{<<":method">>, <<"GET">>},
{<<":method">>, <<"GET">>},
{<<":scheme">>, <<"http">>},