From 6c3f50ad5d2f28e3a5e1b7a540082dd93b79caa9 Mon Sep 17 00:00:00 2001 From: David West Date: Wed, 8 Jan 2025 11:42:54 -0600 Subject: [PATCH] fix: Resolve streaming bug in MemoryWebClient (#959) Improve web client streaming performance --- clients/dotnet/WebClient/MemoryWebClient.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clients/dotnet/WebClient/MemoryWebClient.cs b/clients/dotnet/WebClient/MemoryWebClient.cs index f767881fd..46baf4158 100644 --- a/clients/dotnet/WebClient/MemoryWebClient.cs +++ b/clients/dotnet/WebClient/MemoryWebClient.cs @@ -368,7 +368,13 @@ public async IAsyncEnumerable AskStreamingAsync( using StringContent content = new(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"); var url = Constants.HttpAskEndpoint.CleanUrlPath(); - HttpResponseMessage response = await this._client.PostAsync(url, content, cancellationToken).ConfigureAwait(false); + using var requestMessage = new HttpRequestMessage(HttpMethod.Post, url); + requestMessage.Content = content; + HttpCompletionOption completionOption = useStreaming + ? HttpCompletionOption.ResponseHeadersRead + : HttpCompletionOption.ResponseContentRead; + + HttpResponseMessage response = await this._client.SendAsync(requestMessage, completionOption, cancellationToken).ConfigureAwait(false); response.EnsureSuccessStatusCode(); if (useStreaming)