Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0] [HTTP/3] Release the stream once the response is sent #90722

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ public static int GetRequestId(QuicStream stream)
return checked((int)stream.Id + 1);
}

public Http3LoopbackStream GetOpenRequest(int requestId = 0)
{
return requestId == 0 ? _currentStream : _openStreams[requestId - 1];
}

public override Task InitializeConnectionAsync()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -195,6 +190,17 @@ public async Task EstablishControlStreamAsync(SettingsEntry[] settingsEntries)
await _outboundControlStream.SendSettingsFrameAsync(settingsEntries);
}

public async Task DisposeCurrentStream()
{
Assert.NotNull(_currentStream);
Assert.True(_currentStreamId >= 0);

await _currentStream.DisposeAsync().ConfigureAwait(false);
_openStreams.Remove((int)_currentStreamId);
_currentStream = null;
_currentStreamId = -4;
}

public override async Task<byte[]> ReadRequestBodyAsync()
{
return await _currentStream.ReadRequestBodyAsync().ConfigureAwait(false);
Expand All @@ -206,24 +212,32 @@ public override async Task<HttpRequestData> ReadRequestDataAsync(bool readBody =
return await stream.ReadRequestDataAsync(readBody).ConfigureAwait(false);
}

public override Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true)
public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "", bool isFinal = true)
{
return GetOpenRequest().SendResponseAsync(statusCode, headers, content, isFinal);
await _currentStream.SendResponseAsync(statusCode, headers, content, isFinal);
if (isFinal)
{
await DisposeCurrentStream().ConfigureAwait(false);
}
}

public override Task SendResponseBodyAsync(byte[] content, bool isFinal = true)
public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true)
{
return GetOpenRequest().SendResponseBodyAsync(content, isFinal);
await _currentStream.SendResponseBodyAsync(content, isFinal);
if (isFinal)
{
await DisposeCurrentStream().ConfigureAwait(false);
}
}

public override Task SendResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null)
{
return GetOpenRequest().SendResponseHeadersAsync(statusCode, headers);
return _currentStream.SendResponseHeadersAsync(statusCode, headers);
}

public override Task SendPartialResponseHeadersAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null)
{
return GetOpenRequest().SendPartialResponseHeadersAsync(statusCode, headers);
return _currentStream.SendPartialResponseHeadersAsync(statusCode, headers);
}

public override async Task<HttpRequestData> HandleRequestAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList<HttpHeaderData> headers = null, string content = "")
Expand Down Expand Up @@ -310,7 +324,7 @@ public async Task WaitForClientDisconnectAsync(bool refuseNewRequests = true)

public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true)
{
await GetOpenRequest().WaitForCancellationAsync(ignoreIncomingData).ConfigureAwait(false);
await _currentStream.WaitForCancellationAsync(ignoreIncomingData).ConfigureAwait(false);
}

public override Task WaitForCloseAsync(CancellationToken cancellationToken)
Expand Down
Loading