@@ -212,6 +212,7 @@ const {
212212 kReset,
213213 kSendHeaders,
214214 kMakeWebtransportStream,
215+ kCloseWebtransportSessionStream,
215216 kSessionApplication,
216217 kSessionTicket,
217218 kTrailers,
@@ -2040,6 +2041,33 @@ class QuicStream {
20402041 return this . #inner. pendingClose . promise ;
20412042 }
20422043
2044+ /**
2045+ * Only for webtransport session streams
2046+ * Closes the webtransport session stream, and also closes
2047+ * connected datastream internally.
2048+ * @param {number|undefined } code optional error code
2049+ * @param {string|undefined } msg optional error message truncated to 1024 bytes
2050+ */
2051+ closeWebtransportSessionStream ( code , msg ) {
2052+ assertIsQuicStream ( this ) ;
2053+ const inner = this . #inner;
2054+ if ( inner . destroying || this . destroyed ) return ;
2055+
2056+ if ( msg !== undefined ) {
2057+ validateString ( msg , 'msg' ) ;
2058+ }
2059+ inner . destroying = true ;
2060+ const handle = this . #handle;
2061+ const error = makeQuicError (
2062+ 'ERR_QUIC_APPLICATION_ERROR' ,
2063+ 'Webtransport error' ,
2064+ 'application' ,
2065+ code ?? 0 ,
2066+ msg ?? '' ) ;
2067+ this [ kFinishClose ] ( error ) ;
2068+ handle . destroy ( ) ;
2069+ }
2070+
20432071 /**
20442072 * Immediately destroys the stream. Any queued data is discarded. If
20452073 * an error is given, the closed promise will be rejected with that
@@ -2603,6 +2631,7 @@ class QuicStream {
26032631 /**
26042632 * Attaches a webtransport session to the stream and sends initial bytes
26052633 * indicating webtransport stream and the session id
2634+ * @param {QuicStream } session Webtransport session stream
26062635 * @returns {boolean } true if it succeeded.
26072636 */
26082637 [ kMakeWebtransportStream ] ( session ) {
@@ -2614,6 +2643,23 @@ class QuicStream {
26142643 return this . #handle. makeWebtransportStream ( session . #handle) ;
26152644 }
26162645
2646+ /**
2647+ * Closes a webtransport session stream and also closes associated data streams
2648+ * Passing optional error code and error message (limited to 1024 bytes).
2649+ * @param {number } code error code
2650+ * @param {string } msg error message limited to 1024 bytes
2651+ * @returns {boolean } true if it succeeded.
2652+ */
2653+ [ kCloseWebtransportSessionStream ] ( code , msg ) {
2654+ if ( this . pending ) {
2655+ debug ( 'pending stream enqueuing closeWebtransportSessionStream with code' , code , ' and msg:' , msg ) ;
2656+ } else {
2657+ debug ( `stream ${ this . id } closeWebtransportSessionStream with code` , code ,
2658+ ' and msg:' , msg ) ;
2659+ }
2660+ return this . #handle. closeWebtransportSessionStream ( session . #handle) ;
2661+ }
2662+
26172663 [ kFinishClose ] ( error ) {
26182664 const inner = this . #inner;
26192665 inner . pendingClose ??= PromiseWithResolvers ( ) ;
0 commit comments