Skip to content

Commit

Permalink
fix: Resolve streaming bug in MemoryWebClient (microsoft#959)
Browse files Browse the repository at this point in the history
Improve web client streaming performance
  • Loading branch information
westdavidr authored Jan 8, 2025
1 parent 3c92e68 commit 6c3f50a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion clients/dotnet/WebClient/MemoryWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,13 @@ public async IAsyncEnumerable<MemoryAnswer> 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)
Expand Down

0 comments on commit 6c3f50a

Please sign in to comment.