Repository navigation
Commit 3be27fc
authored
.Net:[OpenAPI] Prevent buffering of streamed responses (#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:
#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 😄1 parent 9363a19 commit 3be27fc
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
| 217 | + | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| |||
0 commit comments