@@ -108,11 +108,6 @@ public static int GetRequestId(QuicStream stream)
108
108
return checked ( ( int ) stream . Id + 1 ) ;
109
109
}
110
110
111
- public Http3LoopbackStream GetOpenRequest ( int requestId = 0 )
112
- {
113
- return requestId == 0 ? _currentStream : _openStreams [ requestId - 1 ] ;
114
- }
115
-
116
111
public override Task InitializeConnectionAsync ( )
117
112
{
118
113
throw new NotImplementedException ( ) ;
@@ -195,6 +190,17 @@ public async Task EstablishControlStreamAsync(SettingsEntry[] settingsEntries)
195
190
await _outboundControlStream . SendSettingsFrameAsync ( settingsEntries ) ;
196
191
}
197
192
193
+ public async Task DisposeCurrentStream ( )
194
+ {
195
+ Assert . NotNull ( _currentStream ) ;
196
+ Assert . True ( _currentStreamId >= 0 ) ;
197
+
198
+ await _currentStream . DisposeAsync ( ) . ConfigureAwait ( false ) ;
199
+ _openStreams . Remove ( ( int ) _currentStreamId ) ;
200
+ _currentStream = null ;
201
+ _currentStreamId = - 4 ;
202
+ }
203
+
198
204
public override async Task < byte [ ] > ReadRequestBodyAsync ( )
199
205
{
200
206
return await _currentStream . ReadRequestBodyAsync ( ) . ConfigureAwait ( false ) ;
@@ -206,24 +212,32 @@ public override async Task<HttpRequestData> ReadRequestDataAsync(bool readBody =
206
212
return await stream . ReadRequestDataAsync ( readBody ) . ConfigureAwait ( false ) ;
207
213
}
208
214
209
- public override Task SendResponseAsync ( HttpStatusCode statusCode = HttpStatusCode . OK , IList < HttpHeaderData > headers = null , string content = "" , bool isFinal = true )
215
+ public override async Task SendResponseAsync ( HttpStatusCode statusCode = HttpStatusCode . OK , IList < HttpHeaderData > headers = null , string content = "" , bool isFinal = true )
210
216
{
211
- return GetOpenRequest ( ) . SendResponseAsync ( statusCode , headers , content , isFinal ) ;
217
+ await _currentStream . SendResponseAsync ( statusCode , headers , content , isFinal ) ;
218
+ if ( isFinal )
219
+ {
220
+ await DisposeCurrentStream ( ) . ConfigureAwait ( false ) ;
221
+ }
212
222
}
213
223
214
- public override Task SendResponseBodyAsync ( byte [ ] content , bool isFinal = true )
224
+ public override async Task SendResponseBodyAsync ( byte [ ] content , bool isFinal = true )
215
225
{
216
- return GetOpenRequest ( ) . SendResponseBodyAsync ( content , isFinal ) ;
226
+ await _currentStream . SendResponseBodyAsync ( content , isFinal ) ;
227
+ if ( isFinal )
228
+ {
229
+ await DisposeCurrentStream ( ) . ConfigureAwait ( false ) ;
230
+ }
217
231
}
218
232
219
233
public override Task SendResponseHeadersAsync ( HttpStatusCode statusCode = HttpStatusCode . OK , IList < HttpHeaderData > headers = null )
220
234
{
221
- return GetOpenRequest ( ) . SendResponseHeadersAsync ( statusCode , headers ) ;
235
+ return _currentStream . SendResponseHeadersAsync ( statusCode , headers ) ;
222
236
}
223
237
224
238
public override Task SendPartialResponseHeadersAsync ( HttpStatusCode statusCode = HttpStatusCode . OK , IList < HttpHeaderData > headers = null )
225
239
{
226
- return GetOpenRequest ( ) . SendPartialResponseHeadersAsync ( statusCode , headers ) ;
240
+ return _currentStream . SendPartialResponseHeadersAsync ( statusCode , headers ) ;
227
241
}
228
242
229
243
public override async Task < HttpRequestData > HandleRequestAsync ( HttpStatusCode statusCode = HttpStatusCode . OK , IList < HttpHeaderData > headers = null , string content = "" )
@@ -310,7 +324,7 @@ public async Task WaitForClientDisconnectAsync(bool refuseNewRequests = true)
310
324
311
325
public override async Task WaitForCancellationAsync ( bool ignoreIncomingData = true )
312
326
{
313
- await GetOpenRequest ( ) . WaitForCancellationAsync ( ignoreIncomingData ) . ConfigureAwait ( false ) ;
327
+ await _currentStream . WaitForCancellationAsync ( ignoreIncomingData ) . ConfigureAwait ( false ) ;
314
328
}
315
329
316
330
public override Task WaitForCloseAsync ( CancellationToken cancellationToken )
0 commit comments