From b63e18d2cc775f1b030b212a4e918be13302e959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 3 Jun 2025 16:02:27 +0200 Subject: [PATCH] WIP close --- test/draft_h3_webtransport_SUITE.erl | 41 ++++++++++++++++++++++++---- test/handlers/wt_echo_h.erl | 6 +++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/test/draft_h3_webtransport_SUITE.erl b/test/draft_h3_webtransport_SUITE.erl index 4bbf2e37..2d5d967e 100644 --- a/test/draft_h3_webtransport_SUITE.erl +++ b/test/draft_h3_webtransport_SUITE.erl @@ -460,11 +460,42 @@ close_wt_session_server(Config) -> %% @todo close_wt_session_app_code_msg_client -%% @todo -%close_wt_session_app_code_server(Config) -> -% error(todo). -%close_wt_session_app_code_msg_server(Config) -> -% error(todo). +close_wt_session_app_code_server(Config) -> + doc("The WT server can close a single session with an application error code. " + "(draft_webtrans_http3 4.6)"), + %% Connect to the WebTransport server. + #{ + conn := Conn, + connect_stream_ref := ConnectStreamRef, + session_id := SessionID + } = do_webtransport_connect(Config), + %% Create a bidi stream, send a special instruction to make it initiate the close. + {ok, LocalStreamRef} = quicer:start_stream(Conn, #{}), + {ok, _} = quicer:send(LocalStreamRef, <<1:2, 16#41:14, 0:2, SessionID:6, + "TEST:close_app_code">>), + %% Receive the CLOSE_WEBTRANSPORT_SESSION capsule on the CONNECT stream. + CloseWTSessionCapsule = cow_capsule:close_wt_session(1234567890, <<>>), + {fin, CloseWTSessionCapsule} = do_receive_data(ConnectStreamRef), + ok. + +close_wt_session_app_code_msg_server(Config) -> + doc("The WT server can close a single session with an application error code " + "and an application error message. (draft_webtrans_http3 4.6)"), + %% Connect to the WebTransport server. + #{ + conn := Conn, + connect_stream_ref := ConnectStreamRef, + session_id := SessionID + } = do_webtransport_connect(Config), + %% Create a bidi stream, send a special instruction to make it initiate the close. + {ok, LocalStreamRef} = quicer:start_stream(Conn, #{}), + {ok, _} = quicer:send(LocalStreamRef, <<1:2, 16#41:14, 0:2, SessionID:6, + "TEST:close_app_code_msg">>), + %% Receive the CLOSE_WEBTRANSPORT_SESSION capsule on the CONNECT stream. + CloseWTSessionCapsule = iolist_to_binary(cow_capsule:close_wt_session(1234567890, + <<"onetwothreefourfivesixseveneightnineten">>)), + {fin, CloseWTSessionCapsule} = do_receive_data(ConnectStreamRef), + ok. %% An endpoint that sends a CLOSE_WEBTRANSPORT_SESSION capsule MUST immediately send a FIN. The endpoint MAY send a STOP_SENDING to indicate it is no longer reading from the CONNECT stream. The recipient MUST either close or reset the stream in response. (6) %% @todo close_wt_session_server_fin diff --git a/test/handlers/wt_echo_h.erl b/test/handlers/wt_echo_h.erl index e919e724..c533b9ee 100644 --- a/test/handlers/wt_echo_h.erl +++ b/test/handlers/wt_echo_h.erl @@ -52,7 +52,11 @@ webtransport_handle(Event = {stream_data, _StreamID, _IsFin, <<"TEST:", Test/bit <<"initiate_close">> -> {[initiate_close], Streams}; <<"close">> -> - {[close], Streams} + {[close], Streams}; + <<"close_app_code">> -> + {[{close, 1234567890}], Streams}; + <<"close_app_code_msg">> -> + {[{close, 1234567890, <<"onetwothreefourfivesixseveneightnineten">>}], Streams} end; webtransport_handle(Event = {stream_data, StreamID, IsFin, Data}, Streams) -> ct:pal("WT handle ~p~n", [Event]),