Skip to content

Commit 6c3f50a

Browse files
authored
fix: Resolve streaming bug in MemoryWebClient (#959)
Improve web client streaming performance
1 parent 3c92e68 commit 6c3f50a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

clients/dotnet/WebClient/MemoryWebClient.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,13 @@ public async IAsyncEnumerable<MemoryAnswer> AskStreamingAsync(
368368
using StringContent content = new(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json");
369369

370370
var url = Constants.HttpAskEndpoint.CleanUrlPath();
371-
HttpResponseMessage response = await this._client.PostAsync(url, content, cancellationToken).ConfigureAwait(false);
371+
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, url);
372+
requestMessage.Content = content;
373+
HttpCompletionOption completionOption = useStreaming
374+
? HttpCompletionOption.ResponseHeadersRead
375+
: HttpCompletionOption.ResponseContentRead;
376+
377+
HttpResponseMessage response = await this._client.SendAsync(requestMessage, completionOption, cancellationToken).ConfigureAwait(false);
372378
response.EnsureSuccessStatusCode();
373379

374380
if (useStreaming)

0 commit comments

Comments
 (0)