123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370 |
- -module(rfc9114_SUITE).
- -compile(export_all).
- -compile(nowarn_export_all).
- -import(ct_helper, [config/2]).
- -import(ct_helper, [doc/1]).
- -include_lib("quicer/include/quicer.hrl").
- all() -> [{group, h3}].
- groups() ->
-
-
-
- [{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, []}
- ]}
- ].
- 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),
-
-
- {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.
- 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),
-
-
- {ok, ControlRef, _Settings} = do_wait_settings(Conn),
-
- {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()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedRequest)),
- EncodedRequest
- ], ?QUIC_SEND_FLAG_FIN),
-
- {ok, Data} = do_receive_data(StreamRef),
- {HLenEnc, HLenBits} = do_guess_int_encoding(Data),
- <<
- 1,
- HLenEnc:2, HLen:HLenBits,
- EncodedResponse:HLen/bytes,
- Rest/bits
- >> = Data,
- {ok, DecodedResponse, _DecData, _DecSt}
- = cow_qpack:decode_field_section(EncodedResponse, 0, cow_qpack:init()),
- #{
- <<":status">> := <<"200">>,
- <<"content-length">> := BodyLen
- } = maps:from_list(DecodedResponse),
- {DLenEnc, DLenBits} = do_guess_int_encoding(Rest),
- <<
- 0,
- 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).
- 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),
-
-
- {ok, ControlRef, _Settings} = do_wait_settings(Conn),
-
- {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()),
- {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>>,
- cow_http3:encode_int(iolist_size(EncodedRequest1)),
- EncodedRequest1,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedRequest2)),
- EncodedRequest2
- ]),
-
- #{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()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<1>>,
- 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()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>,
- <<1>>,
- 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()),
- {ok, _} = quicer:send(StreamRef, [
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{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">>, <<"/">>},
- {<<"content-length">>, <<"13">>}
- ], 0, cow_qpack:init()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedTrailers)),
- EncodedTrailers,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{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()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedTrailers)),
- EncodedTrailers,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{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()),
- {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>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedTrailers1)),
- EncodedTrailers1,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedTrailers2)),
- EncodedTrailers2
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{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()),
- {ok, _} = quicer:send(StreamRef, [
- cow_http3:encode_int(Type),
- cow_http3:encode_int(iolist_size(Bytes)),
- Bytes,
- <<1>>,
- 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()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- cow_http3:encode_int(Type),
- 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()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>,
- cow_http3:encode_int(Type),
- 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">>, <<"/">>},
- {<<"content-length">>, <<"13">>}
- ], 0, cow_qpack:init()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedTrailers)),
- EncodedTrailers,
- cow_http3:encode_int(Type),
- 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()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>,
- cow_http3:encode_int(Type),
- cow_http3:encode_int(iolist_size(Bytes)),
- Bytes,
- <<1>>,
- 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()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(6),
- <<"Hello ">>,
- cow_http3:encode_int(Type),
- cow_http3:encode_int(iolist_size(Bytes)),
- Bytes,
- <<0>>,
- 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()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello server!">>,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedTrailers)),
- EncodedTrailers,
- cow_http3:encode_int(Type),
- 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,
-
- case lists:member(Type, [
- 16#0, 16#1, 16#3, 16#4, 16#5, 16#7, 16#d,
- 16#2, 16#6, 16#8, 16#9
- ]) 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()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(24),
- <<"13\r\nHello server!\r\n0\r\n\r\n">>
- ]),
-
- #{reason := h3_message_error} = do_wait_stream_aborted(StreamRef),
- ok.
- 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?">>}
- ).
- 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()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"content-type">>, <<"text/plain">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<1>>,
- 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">>}
- ).
- 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()),
- {ok, EncodedTrailers, _EncData2, _EncSt} = cow_qpack:encode_field_section([
- {<<"x-checksum">>, <<"md5:4cc909a007407f3706399b6496babec3">>},
- {<<":path">>, <<"/">>}
- ], 0, EncSt0),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(10000),
- <<0:10000/unit:8>>,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedTrailers)),
- EncodedTrailers
- ]),
-
- #{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">>, <<"/">>}
- ]).
- 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">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>}
- ]).
- reject_missing_pseudo_header_scheme(Config) ->
- doc("A request without a scheme 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">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>}
- ]).
- reject_many_pseudo_header_scheme(Config) ->
- doc("A request containing more than one scheme 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">>},
- {<<":scheme">>, <<"http">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>}
- ]).
- reject_missing_pseudo_header_authority(Config) ->
- doc("A request without an authority or host 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">>},
- {<<":path">>, <<"/">>}
- ]).
- accept_host_header_on_missing_pseudo_header_authority(Config) ->
- doc("A request without an authority but with a host header must be accepted. "
- "(RFC9114 4.3.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">>},
- {<<":path">>, <<"/">>},
- {<<"host">>, <<"localhost">>}
- ], 0, cow_qpack:init()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders
- ], ?QUIC_SEND_FLAG_FIN),
- #{
- headers := #{<<":status">> := <<"200">>},
- body := <<"Hello world!">>
- } = do_receive_response(StreamRef),
- ok.
- reject_many_pseudo_header_authority(Config) ->
- doc("A request containing more than one authority 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">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>}
- ]).
- reject_missing_pseudo_header_path(Config) ->
- doc("A request without a 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">>}
- ]).
- reject_many_pseudo_header_path(Config) ->
- doc("A request containing more than one 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">>, <<"/">>},
- {<<":path">>, <<"/">>}
- ]).
- do_reject_malformed_header(Config, Header) ->
- do_reject_malformed_headers(Config, [
- {<<":method">>, <<"GET">>},
- {<<":scheme">>, <<"https">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>},
- Header
- ]).
- do_reject_malformed_headers(Config, Headers) ->
- #{conn := Conn} = do_connect(Config),
- {ok, StreamRef} = quicer:start_stream(Conn, #{}),
- {ok, EncodedHeaders, _EncData1, _EncSt0}
- = cow_qpack:encode_field_section(Headers, 0, cow_qpack:init()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders
- ]),
-
- #{reason := h3_message_error} = do_wait_stream_aborted(StreamRef),
- ok.
- bidi_allow_at_least_a_hundred(Config) ->
- doc("Endpoints must allow the peer to create at least "
- "one hundred bidirectional streams. (RFC9114 6.1"),
- #{conn := Conn} = do_connect(Config),
- receive
- {quic, streams_available, Conn, #{bidi_streams := NumStreams}} ->
- true = NumStreams >= 100,
- ok
- after 5000 ->
- error(timeout)
- end.
- unidi_allow_at_least_three(Config) ->
- doc("Endpoints must allow the peer to create at least "
- "three unidirectional streams. (RFC9114 6.2"),
- #{conn := Conn} = do_connect(Config),
-
- receive
- {quic, streams_available, Conn, #{unidi_streams := NumStreams}} ->
- true = NumStreams >= 3,
- ok
- after 5000 ->
- error(timeout)
- end,
-
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef, [<<0>>, SettingsBin]),
- {ok, EncoderRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(EncoderRef, <<2>>),
- {ok, DecoderRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(DecoderRef, <<3>>),
-
- fun Loop() ->
- receive
-
- {quic, dgram_state_changed, Conn, _} ->
- Loop();
- {quic, peer_needs_streams, Conn, _} ->
- Loop();
-
- Msg ->
- error(Msg)
- after 1000 ->
- ok
- end
- end().
- unidi_create_critical_first(Config) ->
- doc("Endpoints should create the HTTP control stream as well as "
- "the QPACK encoder and decoder streams first. (RFC9114 6.2"),
-
- #{conn := Conn} = do_connect(Config, #{peer_unidi_stream_count => 3}),
- Unidi1 = do_accept_qpack_stream(Conn),
- Unidi2 = do_accept_qpack_stream(Conn),
- case {Unidi1, Unidi2} of
- {{encoder, _}, {decoder, _}} ->
- ok;
- {{decoder, _}, {encoder, _}} ->
- ok
- end.
- do_accept_qpack_stream(Conn) ->
- receive
- {quic, new_stream, StreamRef, #{flags := Flags}} ->
- ok = quicer:setopt(StreamRef, active, true),
- true = quicer:is_unidirectional(Flags),
- receive {quic, <<Type>>, StreamRef, _} ->
- {case Type of
- 2 -> encoder;
- 3 -> decoder
- end, StreamRef}
- after 5000 ->
- error(timeout)
- end
- after 5000 ->
- error(timeout)
- end.
- unidi_abort_unknown_type(Config) ->
- doc("Receipt of an unknown stream type must be aborted "
- "with an H3_STREAM_CREATION_ERROR stream error. (RFC9114 6.2, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
-
- {ok, StreamRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(StreamRef, [
- cow_http3:encode_int(1 + do_reserved_type()),
- rand:bytes(rand:uniform(4096))
- ]),
-
- #{reason := h3_stream_creation_error} = do_wait_stream_aborted(StreamRef),
- ok.
- unidi_abort_reserved_type(Config) ->
- doc("Receipt of a reserved stream type must be aborted "
- "with an H3_STREAM_CREATION_ERROR stream error. "
- "(RFC9114 6.2, RFC9114 6.2.3, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
-
- {ok, StreamRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(StreamRef, [
- cow_http3:encode_int(do_reserved_type()),
- rand:bytes(rand:uniform(4096))
- ]),
-
- #{reason := h3_stream_creation_error} = do_wait_stream_aborted(StreamRef),
- ok.
- control_reject_first_frame_data(Config) ->
- doc("The first frame on a control stream must be a SETTINGS frame "
- "or the connection must be closed with an H3_MISSING_SETTINGS "
- "connection error. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<0>>,
- cow_http3:encode_int(12),
- <<"Hello world!">>
- ]),
-
- #{reason := h3_missing_settings} = do_wait_connection_closed(Conn),
- ok.
- control_reject_first_frame_headers(Config) ->
- doc("The first frame on a control stream must be a SETTINGS frame "
- "or the connection must be closed with an H3_MISSING_SETTINGS "
- "connection error. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, EncodedHeaders, _EncData, _EncSt} = cow_qpack:encode_field_section([
- {<<":method">>, <<"GET">>},
- {<<":scheme">>, <<"https">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>},
- {<<"content-length">>, <<"0">>}
- ], 0, cow_qpack:init()),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders
- ]),
-
- #{reason := h3_missing_settings} = do_wait_connection_closed(Conn),
- ok.
- control_reject_first_frame_cancel_push(Config) ->
- doc("The first frame on a control stream must be a SETTINGS frame "
- "or the connection must be closed with an H3_MISSING_SETTINGS "
- "connection error. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<3>>,
- cow_http3:encode_int(1),
- cow_http3:encode_int(0)
- ]),
-
- #{reason := h3_missing_settings} = do_wait_connection_closed(Conn),
- ok.
- control_accept_first_frame_settings(Config) ->
- doc("The first frame on a control stream "
- "must be a SETTINGS frame. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin
- ]),
-
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- Reason = cow_http3:code_to_error(Code),
- error(Reason)
- after 1000 ->
- ok
- end.
- control_reject_first_frame_push_promise(Config) ->
- doc("The first frame on a control stream must be a SETTINGS frame "
- "or the connection must be closed with an H3_MISSING_SETTINGS "
- "connection error. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, EncodedHeaders, _EncData, _EncSt} = cow_qpack:encode_field_section([
- {<<":method">>, <<"GET">>},
- {<<":scheme">>, <<"https">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>},
- {<<"content-length">>, <<"0">>}
- ], 0, cow_qpack:init()),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<5>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders) + 1),
- cow_http3:encode_int(0),
- EncodedHeaders
- ]),
-
- #{reason := h3_missing_settings} = do_wait_connection_closed(Conn),
- ok.
- control_reject_first_frame_goaway(Config) ->
- doc("The first frame on a control stream must be a SETTINGS frame "
- "or the connection must be closed with an H3_MISSING_SETTINGS "
- "connection error. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<7>>,
- cow_http3:encode_int(1),
- cow_http3:encode_int(0)
- ]),
-
- #{reason := h3_missing_settings} = do_wait_connection_closed(Conn),
- ok.
- control_reject_first_frame_max_push_id(Config) ->
- doc("The first frame on a control stream must be a SETTINGS frame "
- "or the connection must be closed with an H3_MISSING_SETTINGS "
- "connection error. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<13>>,
- cow_http3:encode_int(1),
- cow_http3:encode_int(0)
- ]),
-
- #{reason := h3_missing_settings} = do_wait_connection_closed(Conn),
- ok.
- control_reject_first_frame_reserved(Config) ->
- doc("The first frame on a control stream must be a SETTINGS frame "
- "or the connection must be closed with an H3_MISSING_SETTINGS "
- "connection error. (RFC9114 6.2.1, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- Len = rand:uniform(512),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- cow_http3:encode_int(do_reserved_type()),
- cow_http3:encode_int(Len),
- rand:bytes(Len)
- ]),
-
- #{reason := h3_missing_settings} = do_wait_connection_closed(Conn),
- ok.
- control_reject_multiple(Config) ->
- doc("Endpoints must not create multiple control streams. (RFC9114 6.2.1)"),
- #{conn := Conn} = do_connect(Config),
-
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, ControlRef1} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef1, [<<0>>, SettingsBin]),
- {ok, ControlRef2} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef2, [<<0>>, SettingsBin]),
-
- #{reason := h3_stream_creation_error} = do_wait_connection_closed(Conn),
- ok.
- control_local_closed_abort(Config) ->
- doc("Endpoints must not close the control stream. (RFC9114 6.2.1)"),
- #{conn := Conn} = do_connect(Config),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef, [<<0>>, SettingsBin]),
-
- timer:sleep(100),
-
- quicer:async_shutdown_stream(ControlRef, ?QUIC_STREAM_SHUTDOWN_FLAG_ABORT, 0),
-
- timer:sleep(1000),
- ct:pal("~p", [process_info(self(), messages)]),
- #{reason := h3_closed_critical_stream} = do_wait_connection_closed(Conn),
- ok.
- control_local_closed_graceful(Config) ->
- doc("Endpoints must not close the control stream. (RFC9114 6.2.1)"),
- #{conn := Conn} = do_connect(Config),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, _} = quicer:send(ControlRef, [<<0>>, SettingsBin]),
-
- quicer:async_shutdown_stream(ControlRef, ?QUIC_STREAM_SHUTDOWN_FLAG_GRACEFUL, 0),
-
- #{reason := h3_closed_critical_stream} = do_wait_connection_closed(Conn),
- ok.
- control_remote_closed_abort(Config) ->
- doc("Endpoints must not close the control stream. (RFC9114 6.2.1)"),
- #{conn := Conn, control := ControlRef} = do_connect(Config),
-
- quicer:async_shutdown_stream(ControlRef, ?QUIC_STREAM_SHUTDOWN_FLAG_ABORT, 0),
-
- #{reason := h3_closed_critical_stream} = do_wait_connection_closed(Conn),
- ok.
- data_frame_can_span_multiple_packets(Config) ->
- doc("HTTP/3 frames can span multiple packets. (RFC9114 7)"),
- #{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">>, <<"/echo/read_body">>},
- {<<"content-length">>, <<"13">>}
- ], 0, cow_qpack:init()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello ">>
- ]),
- timer:sleep(100),
- {ok, _} = quicer:send(StreamRef, [
- <<"server!">>
- ], ?QUIC_SEND_FLAG_FIN),
- #{
- headers := #{<<":status">> := <<"200">>},
- body := <<"Hello server!">>
- } = do_receive_response(StreamRef),
- ok.
- headers_frame_can_span_multiple_packets(Config) ->
- doc("HTTP/3 frames can span multiple packets. (RFC9114 7)"),
- #{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()),
- Half = iolist_size(EncodedHeaders) div 2,
- <<EncodedHeadersPart1:Half/binary, EncodedHeadersPart2/bits>>
- = iolist_to_binary(EncodedHeaders),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeadersPart1
- ]),
- timer:sleep(100),
- {ok, _} = quicer:send(StreamRef, [
- EncodedHeadersPart2
- ]),
- #{
- headers := #{<<":status">> := <<"200">>},
- body := <<"Hello world!">>
- } = do_receive_response(StreamRef),
- ok.
- settings_frame_can_span_multiple_packets(Config) ->
- doc("HTTP/3 frames can span multiple packets. (RFC9114 7)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- <<SettingsPart1:1/binary, SettingsPart2/bits>> = SettingsBin,
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsPart1
- ]),
- timer:sleep(100),
- {ok, _} = quicer:send(ControlRef, [
- SettingsPart2
- ]),
-
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- Reason = cow_http3:code_to_error(Code),
- error(Reason)
- after 1000 ->
- ok
- end.
- goaway_frame_can_span_multiple_packets(Config) ->
- doc("HTTP/3 frames can span multiple packets. (RFC9114 7)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<7>>, cow_http3:encode_int(1)
- ]),
- timer:sleep(100),
- {ok, _} = quicer:send(ControlRef, [
- cow_http3:encode_int(0)
- ]),
-
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- h3_no_error = cow_http3:code_to_error(Code),
- ok;
-
-
- {quic, shutdown, Conn, success} ->
- ok
- after 1000 ->
- error(timeout)
- end.
- max_push_id_frame_can_span_multiple_packets(Config) ->
- doc("HTTP/3 frames can span multiple packets. (RFC9114 7)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<13>>, cow_http3:encode_int(1)
- ]),
- timer:sleep(100),
- {ok, _} = quicer:send(ControlRef, [
- cow_http3:encode_int(0)
- ]),
-
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- Reason = cow_http3:code_to_error(Code),
- error(Reason)
- after 1000 ->
- ok
- end.
- headers_frame_too_short(Config) ->
- doc("Frames that terminate before the end of identified fields "
- "must be rejected with an H3_FRAME_ERROR connection error. "
- "(RFC9114 7.1, RFC9114 10.8)"),
- #{conn := Conn} = do_connect(Config),
- {ok, StreamRef} = quicer:start_stream(Conn, #{}),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(0)
- ]),
-
- #{reason := h3_frame_error} = do_wait_connection_closed(Conn),
- ok.
- goaway_frame_too_short(Config) ->
- doc("Frames that terminate before the end of identified fields "
- "must be rejected with an H3_FRAME_ERROR connection error. "
- "(RFC9114 7.1, RFC9114 10.8)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<7>>, cow_http3:encode_int(0)
- ]),
-
- #{reason := h3_frame_error} = do_wait_connection_closed(Conn),
- ok.
- max_push_id_frame_too_short(Config) ->
- doc("Frames that terminate before the end of identified fields "
- "must be rejected with an H3_FRAME_ERROR connection error. "
- "(RFC9114 7.1, RFC9114 10.8)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<13>>, cow_http3:encode_int(0)
- ]),
-
- #{reason := h3_frame_error} = do_wait_connection_closed(Conn),
- ok.
- data_frame_truncated(Config) ->
- doc("Truncated frames must be rejected with an "
- "H3_FRAME_ERROR connection error. (RFC9114 7.1, RFC9114 10.8)"),
- #{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">>, <<"/echo/read_body">>},
- {<<"content-length">>, <<"13">>}
- ], 0, cow_qpack:init()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders,
- <<0>>,
- cow_http3:encode_int(13),
- <<"Hello ">>
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{reason := h3_frame_error} = do_wait_connection_closed(Conn),
- ok.
- headers_frame_truncated(Config) ->
- doc("Truncated frames must be rejected with an "
- "H3_FRAME_ERROR connection error. (RFC9114 7.1, RFC9114 10.8)"),
- #{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()),
- {ok, _} = quicer:send(StreamRef, [
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders))
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{reason := h3_frame_error} = do_wait_connection_closed(Conn),
- ok.
- goaway_frame_too_long(Config) ->
- doc("Frames that contain additional bytes after the end of identified fields "
- "must be rejected with an H3_FRAME_ERROR connection error. "
- "(RFC9114 7.1, RFC9114 10.8)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<7>>, cow_http3:encode_int(3),
- <<0, 1, 2>>
- ]),
-
- #{reason := h3_frame_error} = do_wait_connection_closed(Conn),
- ok.
- max_push_id_frame_too_long(Config) ->
- doc("Frames that contain additional bytes after the end of identified fields "
- "must be rejected with an H3_FRAME_ERROR connection error. "
- "(RFC9114 7.1, RFC9114 10.8)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<13>>, cow_http3:encode_int(9),
- <<0, 1, 2, 3, 4, 5, 6, 7, 8>>
- ]),
-
- #{reason := h3_frame_error} = do_wait_connection_closed(Conn),
- ok.
- data_frame_rejected_on_control_stream(Config) ->
- doc("DATA frames received on the control stream must be rejected "
- "with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.1)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<0>>,
- cow_http3:encode_int(12),
- <<"Hello world!">>
- ]),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- headers_frame_rejected_on_control_stream(Config) ->
- doc("HEADERS frames received on the control stream must be rejected "
- "with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.2)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, EncodedHeaders, _EncData, _EncSt} = cow_qpack:encode_field_section([
- {<<":method">>, <<"GET">>},
- {<<":scheme">>, <<"https">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>},
- {<<"content-length">>, <<"0">>}
- ], 0, cow_qpack:init()),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders
- ]),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- settings_twice(Config) ->
- doc("Receipt of a second SETTINGS frame on the control stream "
- "must be rejected with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.4)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- SettingsBin
- ]),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- settings_on_bidi_stream(Config) ->
- doc("Receipt of a SETTINGS frame on a bidirectional stream "
- "must be rejected with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.4)"),
- #{conn := Conn} = do_connect(Config),
- {ok, StreamRef} = quicer:start_stream(Conn, #{}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([
- {<<":method">>, <<"GET">>},
- {<<":scheme">>, <<"https">>},
- {<<":authority">>, <<"localhost">>},
- {<<":path">>, <<"/">>},
- {<<"content-length">>, <<"0">>}
- ], 0, cow_qpack:init()),
- {ok, _} = quicer:send(StreamRef, [
- SettingsBin,
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedRequest)),
- EncodedRequest
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- settings_identifier_twice(Config) ->
- doc("Receipt of a duplicate SETTINGS identifier must be rejected "
- "with an H3_SETTINGS_ERROR connection error. (RFC9114 7.2.4)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- SettingsPayload = [
- cow_http3:encode_int(6), cow_http3:encode_int(4096),
- cow_http3:encode_int(6), cow_http3:encode_int(8192)
- ],
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<4>>,
- cow_http3:encode_int(iolist_size(SettingsPayload)),
- SettingsPayload
- ]),
-
- #{reason := h3_settings_error} = do_wait_connection_closed(Conn),
- ok.
- settings_ignore_unknown_identifier(Config) ->
- doc("Unknown SETTINGS identifiers must be ignored (RFC9114 7.2.4, RFC9114 9)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- SettingsPayload = [
- cow_http3:encode_int(999), cow_http3:encode_int(4096)
- ],
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<4>>,
- cow_http3:encode_int(iolist_size(SettingsPayload)),
- SettingsPayload
- ]),
-
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- Reason = cow_http3:code_to_error(Code),
- error(Reason)
- after 1000 ->
- ok
- end.
- settings_ignore_reserved_identifier(Config) ->
- doc("Reserved SETTINGS identifiers must be ignored (RFC9114 7.2.4.1)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- SettingsPayload = [
- cow_http3:encode_int(do_reserved_type()), cow_http3:encode_int(4096)
- ],
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<4>>,
- cow_http3:encode_int(iolist_size(SettingsPayload)),
- SettingsPayload
- ]),
-
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- Reason = cow_http3:code_to_error(Code),
- error(Reason)
- after 1000 ->
- ok
- end.
- settings_reject_http2_0x02(Config) ->
- do_settings_reject_http2(Config, 2, 1).
- settings_reject_http2_0x03(Config) ->
- do_settings_reject_http2(Config, 3, 100).
- settings_reject_http2_0x04(Config) ->
- do_settings_reject_http2(Config, 4, 128000).
- settings_reject_http2_0x05(Config) ->
- do_settings_reject_http2(Config, 5, 1000000).
- do_settings_reject_http2(Config, Identifier, Value) ->
- doc("Receipt of an unused HTTP/2 SETTINGS identifier must be rejected "
- "with an H3_SETTINGS_ERROR connection error. (RFC9114 7.2.4, RFC9114 11.2.2)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- SettingsPayload = [
- cow_http3:encode_int(Identifier), cow_http3:encode_int(Value)
- ],
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- <<4>>,
- cow_http3:encode_int(iolist_size(SettingsPayload)),
- SettingsPayload
- ]),
-
- #{reason := h3_settings_error} = do_wait_connection_closed(Conn),
- ok.
- goaway_on_bidi_stream(Config) ->
- doc("Receipt of a GOAWAY frame on a bidirectional stream "
- "must be rejected with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.6)"),
- #{conn := Conn} = do_connect(Config),
- {ok, StreamRef} = quicer:start_stream(Conn, #{}),
- {ok, _} = quicer:send(StreamRef, [
- <<7>>, cow_http3:encode_int(1), cow_http3:encode_int(0)
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- max_push_id_on_bidi_stream(Config) ->
- doc("Receipt of a MAX_PUSH_ID frame on a bidirectional stream "
- "must be rejected with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.7)"),
- #{conn := Conn} = do_connect(Config),
- {ok, StreamRef} = quicer:start_stream(Conn, #{}),
- {ok, _} = quicer:send(StreamRef, [
- <<13>>, cow_http3:encode_int(1), cow_http3:encode_int(0)
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- max_push_id_reject_lower(Config) ->
- doc("Receipt of a MAX_PUSH_ID value lower than previously received "
- "must be rejected with an H3_ID_ERROR connection error. (RFC9114 7.2.7)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- <<13>>, cow_http3:encode_int(1), cow_http3:encode_int(20),
- <<13>>, cow_http3:encode_int(1), cow_http3:encode_int(10)
- ]),
-
- #{reason := h3_id_error} = do_wait_connection_closed(Conn),
- ok.
- reserved_on_control_stream(Config) ->
- doc("Receipt of a reserved frame type on a control stream "
- "must be ignored. (RFC9114 7.2.8)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- Len = rand:uniform(512),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- cow_http3:encode_int(do_reserved_type()),
- cow_http3:encode_int(Len),
- rand:bytes(Len)
- ]),
-
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- Reason = cow_http3:code_to_error(Code),
- error(Reason)
- after 1000 ->
- ok
- end.
- reserved_reject_http2_0x02_control(Config) ->
- do_reserved_reject_http2_control(Config, 2).
- reserved_reject_http2_0x06_control(Config) ->
- do_reserved_reject_http2_control(Config, 6).
- reserved_reject_http2_0x08_control(Config) ->
- do_reserved_reject_http2_control(Config, 8).
- reserved_reject_http2_0x09_control(Config) ->
- do_reserved_reject_http2_control(Config, 9).
- do_reserved_reject_http2_control(Config, Type) ->
- doc("Receipt of an unused HTTP/2 frame type must be rejected "
- "with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.8, RFC9114 11.2.1)"),
- #{conn := Conn} = do_connect(Config),
- {ok, ControlRef} = quicer:start_stream(Conn,
- #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}),
- {ok, SettingsBin, _HTTP3Machine0} = cow_http3_machine:init(client, #{}),
- Len = rand:uniform(512),
- {ok, _} = quicer:send(ControlRef, [
- <<0>>,
- SettingsBin,
- cow_http3:encode_int(Type),
- cow_http3:encode_int(Len),
- rand:bytes(Len)
- ]),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- reserved_reject_http2_0x02_bidi(Config) ->
- do_reserved_reject_http2_bidi(Config, 2).
- reserved_reject_http2_0x06_bidi(Config) ->
- do_reserved_reject_http2_bidi(Config, 6).
- reserved_reject_http2_0x08_bidi(Config) ->
- do_reserved_reject_http2_bidi(Config, 8).
- reserved_reject_http2_0x09_bidi(Config) ->
- do_reserved_reject_http2_bidi(Config, 9).
- do_reserved_reject_http2_bidi(Config, Type) ->
- doc("Receipt of an unused HTTP/2 frame type must be rejected "
- "with an H3_FRAME_UNEXPECTED connection error. (RFC9114 7.2.8, RFC9114 11.2.1)"),
- #{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()),
- Len = rand:uniform(512),
- {ok, _} = quicer:send(StreamRef, [
- cow_http3:encode_int(Type),
- cow_http3:encode_int(Len),
- rand:bytes(Len),
- <<1>>,
- cow_http3:encode_int(iolist_size(EncodedHeaders)),
- EncodedHeaders
- ], ?QUIC_SEND_FLAG_FIN),
-
- #{reason := h3_frame_unexpected} = do_wait_connection_closed(Conn),
- ok.
- do_reserved_type() ->
- 16#1f * (rand:uniform(148764065110560900) - 1) + 16#21.
- do_connect(Config) ->
- do_connect(Config, #{}).
- do_connect(Config, Opts) ->
- {ok, Conn} = quicer:connect("localhost", config(port, Config),
- Opts#{alpn => ["h3"], verify => none}, 5000),
-
-
- {ok, ControlRef, Settings} = do_wait_settings(Conn),
- #{
- conn => Conn,
- control => ControlRef,
- settings => Settings
- }.
- do_wait_settings(Conn) ->
- receive
- {quic, new_stream, StreamRef, #{flags := Flags}} ->
- ok = quicer:setopt(StreamRef, active, true),
- true = quicer:is_unidirectional(Flags),
- receive {quic, <<
- 0,
- SettingsFrame/bits
- >>, StreamRef, _} ->
- {ok, {settings, Settings}, <<>>} = cow_http3:parse(SettingsFrame),
- {ok, StreamRef, Settings}
- after 5000 ->
- {error, timeout}
- end
- after 5000 ->
- {error, timeout}
- end.
- do_receive_data(StreamRef) ->
- receive
- {quic, Data, StreamRef, _Flags} when is_binary(Data) ->
- {ok, Data}
- after 5000 ->
- {error, timeout}
- end.
- do_guess_int_encoding(Data) ->
- SizeWithLen = byte_size(Data) - 1,
- if
- SizeWithLen < 64 + 1 ->
- {0, 6};
- SizeWithLen < 16384 + 2 ->
- {1, 14};
- SizeWithLen < 1073741824 + 4 ->
- {2, 30};
- SizeWithLen < 4611686018427387904 + 8 ->
- {3, 62}
- end.
- do_wait_peer_send_shutdown(StreamRef) ->
- receive
- {quic, peer_send_shutdown, StreamRef, undefined} ->
- ok
- after 5000 ->
- {error, timeout}
- end.
- do_wait_stream_aborted(StreamRef) ->
- receive
- {quic, peer_send_aborted, StreamRef, Code} ->
- Reason = cow_http3:code_to_error(Code),
- #{reason => Reason};
- {quic, peer_receive_aborted, StreamRef, Code} ->
- Reason = cow_http3:code_to_error(Code),
- #{reason => Reason}
- after 5000 ->
- {error, timeout}
- end.
- do_wait_stream_closed(StreamRef) ->
- receive
- {quic, stream_closed, StreamRef, #{error := Error, is_conn_shutdown := false}} ->
- 0 = Error,
- ok
- after 5000 ->
- {error, timeout}
- end.
- do_receive_response(StreamRef) ->
- {ok, Data} = do_receive_data(StreamRef),
- {HLenEnc, HLenBits} = do_guess_int_encoding(Data),
- <<
- 1,
- HLenEnc:2, HLen:HLenBits,
- EncodedResponse:HLen/bytes,
- Rest/bits
- >> = Data,
- {ok, DecodedResponse, _DecData, _DecSt}
- = cow_qpack:decode_field_section(EncodedResponse, 0, cow_qpack:init()),
- Headers = maps:from_list(DecodedResponse),
- #{<<"content-length">> := BodyLen} = Headers,
- {DLenEnc, DLenBits} = do_guess_int_encoding(Rest),
- Body = case Rest of
- <<>> ->
- <<>>;
- <<
- 0,
- DLenEnc:2, DLen:DLenBits,
- Body0:DLen/bytes
- >> ->
- BodyLen = integer_to_binary(byte_size(Body0)),
- Body0
- end,
- ok = do_wait_peer_send_shutdown(StreamRef),
- #{
- headers => Headers,
- body => Body
- }.
- do_wait_connection_closed(Conn) ->
- receive
- {quic, shutdown, Conn, {unknown_quic_status, Code}} ->
- Reason = cow_http3:code_to_error(Code),
- #{reason => Reason}
- after 5000 ->
- {error, timeout}
- end.
|