-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClientModel Prototype: Change approach to response.Content, with buffering in transport instead of policy #13
base: core2-move-buffering-to-transport
Are you sure you want to change the base?
Conversation
@@ -8,8 +8,11 @@ namespace System.ClientModel.Primitives; | |||
|
|||
public partial class HttpClientPipelineTransport | |||
{ | |||
private class HttpPipelineResponse : PipelineResponse | |||
private class HttpClientPipelineResponse : PipelineResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this type
{ | ||
_httpResponse = httpResponse ?? throw new ArgumentNullException(nameof(httpResponse)); | ||
_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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this into the constructor
@@ -62,8 +58,9 @@ protected virtual void Dispose(bool disposing) | |||
{ | |||
if (disposing && !_disposed) | |||
{ | |||
var httpResponse = _httpResponse; | |||
httpResponse?.Dispose(); | |||
// The transport is responsible for disposing the HttpResponseMessage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move where this happens?
{ | ||
message.Response.ContentStream = contentStream; | ||
} | ||
responseMessage.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dispose this in the transport instead of in the response
} | ||
|
||
if (!message.BufferResponse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this logic into Response so transport just makes a simple call to response.TryBufferContent(message.BufferContent)
@@ -11,23 +11,23 @@ namespace System.ClientModel.Primitives; | |||
|
|||
internal class HttpClientResponseHeaders : PipelineResponseHeaders | |||
{ | |||
private readonly HttpResponseMessage _httpResponse; | |||
private readonly HttpHeaders _httpHeaders; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't store the whole response message, just the part we need
@@ -146,35 +146,4 @@ private static string JoinHeaderValues(IEnumerable<string> values) | |||
} | |||
#endif | |||
#endregion | |||
|
|||
private static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetHeadersListValues(HttpHeaders headers, HttpContent? content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this code, which is never used
@@ -73,7 +76,7 @@ public virtual BinaryData Content | |||
|
|||
protected virtual void SetIsErrorCore(bool isError) => _isError = isError; | |||
|
|||
internal TimeSpan NetworkTimeout { get; set; } = ClientPipeline.DefaultNetworkTimeout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this initialization?
{ | ||
// No need to buffer content. | ||
return; | ||
} | ||
|
||
MemoryStream bufferStream = new(); | ||
|
||
// TODO: Come back and optimize this - for now, just a POC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this as we no longer need it.
Investigation into Azure#41080