ClientModel Prototype: Change approach to response.Content, with buffering in transport instead of policy#13
Conversation
| public partial class HttpClientPipelineTransport | ||
| { | ||
| private class HttpPipelineResponse : PipelineResponse | ||
| private class HttpClientPipelineResponse : PipelineResponse |
| _httpResponseContent = _httpResponse.Content; | ||
|
|
||
| // Don't let anyone dispose the content, which is used by headers. | ||
| _httpResponse.Content = null; |
There was a problem hiding this comment.
Add this into the constructor
| { | ||
| var httpResponse = _httpResponse; | ||
| httpResponse?.Dispose(); | ||
| // The transport is responsible for disposing the HttpResponseMessage. |
There was a problem hiding this comment.
Move where this happens?
| { | ||
| message.Response.ContentStream = contentStream; | ||
| } | ||
| responseMessage.Dispose(); |
There was a problem hiding this comment.
Dispose this in the transport instead of in the response
| await message.Response!.UpdateContentAsync(message.BufferResponse, userToken, joinedTokenSource).ConfigureAwait(false); | ||
| } | ||
|
|
||
| if (!message.BufferResponse) |
There was a problem hiding this comment.
Move this logic into Response so transport just makes a simple call to response.TryBufferContent(message.BufferContent)
| internal class HttpClientResponseHeaders : PipelineResponseHeaders | ||
| { | ||
| private readonly HttpResponseMessage _httpResponse; | ||
| private readonly HttpHeaders _httpHeaders; |
There was a problem hiding this comment.
Don't store the whole response message, just the part we need
| #endif | ||
| #endregion | ||
|
|
||
| private static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetHeadersListValues(HttpHeaders headers, HttpContent? content) |
There was a problem hiding this comment.
Remove this code, which is never used
|
|
||
| protected virtual void SetIsErrorCore(bool isError) => _isError = isError; | ||
|
|
||
| internal TimeSpan NetworkTimeout { get; set; } = ClientPipeline.DefaultNetworkTimeout; |
There was a problem hiding this comment.
Can we remove this initialization?
|
|
||
| MemoryStream bufferStream = new(); | ||
|
|
||
| // TODO: Come back and optimize this - for now, just a POC. |
There was a problem hiding this comment.
We will want to optimize the implementation
| /// <remarks> | ||
| /// Throws <see cref="InvalidOperationException"/> when <see cref="PipelineResponse.ContentStream"/> is not a <see cref="MemoryStream"/>. | ||
| /// </remarks> | ||
| public new virtual BinaryData Content => base.Content; |
There was a problem hiding this comment.
Remove this as we no longer need it.
Investigation into Azure#41080