Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net:[OpenAPI] Prevent buffering of streamed responses (microsoft#8557)
### Motivation and Context Today, the `RestApiOperationRunner` reads the entire response body into a memory buffer before the `HttpClient.SendAsync` operation returns control to the calling code. This approach is not efficient for scenarios where the calling code can start working with the stream content as soon as it becomes available, without waiting until it's fully read and buffered. ### Description This PR specifies the `HttpCompletionOption.ResponseHeadersRead` option as an argument of the `HttpClient.SendAsync` method to indicate that the method should return execution control to the calling code as soon as headers are available but before the content is read. If the calling code specifies a custom HTTP content reader to read the response content as a stream, then the calling code will start receiving the streamed content as soon as its first bytes are available. In all other cases, when the response content is consumed as a string using the `ReadAsStringAsync` method or as a byte array using the `ReadAsByteArrayAsync` method, the response content will be buffered in memory and become available when fully read from the wire. Addresses: microsoft#8070 (comment) ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄