Skip to content
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

Open
wants to merge 8 commits into
base: core2-move-buffering-to-transport
Choose a base branch
from

Conversation

annelo-msft
Copy link
Owner

Investigation into Azure#41080

@@ -8,8 +8,11 @@ namespace System.ClientModel.Primitives;

public partial class HttpClientPipelineTransport
{
private class HttpPipelineResponse : PipelineResponse
private class HttpClientPipelineResponse : PipelineResponse
Copy link
Owner Author

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;
Copy link
Owner Author

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.
Copy link
Owner Author

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();
Copy link
Owner Author

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)
Copy link
Owner Author

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;
Copy link
Owner Author

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)
Copy link
Owner Author

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;
Copy link
Owner Author

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.
Copy link
Owner Author

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;
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant