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

Add CreateMessage method to the pipeline #7636

Merged
merged 13 commits into from
Sep 19, 2019

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Sep 16, 2019

Fixes: #7519

Breaking change

SendAsync with bufferResponse parameter is removed, CreateMessage should be used for advanced scenarios.

Before:

var request = pipeline.CreateRequest();
pipeline.SendAsync(request, bufferResponse: true, cancellationToken);

After:

var message = pipeline.CreateMessage();
message.BufferResponse = true;
message.CancellationToken = cancellationToken;
pipeline.SendAsync(message);

@pakrym
Copy link
Contributor Author

pakrym commented Sep 16, 2019

#7641
#7640

@pakrym pakrym requested a review from tg-msft September 18, 2019 17:00
Copy link
Member

@tg-msft tg-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome - this is a very good change.

sdk/core/Azure.Core/src/Pipeline/HttpPipeline.cs Outdated Show resolved Hide resolved
@@ -60,5 +60,76 @@ public void SetProperty(string name, object value)

_properties[name] = value;
}

public Stream? PreserveResponseContent()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name PreserveResponseContent makes me think this should be a bool. I'm not sure of a better name though. AcquireResponseContentOwnership? GetAndLockResponseContent? ClaimResponseContent? Maybe @KrzysztofCwalina has an idea for this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExtractResponseContent?


private static Exception CreateException()
{
return new InvalidOperationException("This operation returns Stream as part of the model type. It should be used instead of the response content stream.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry about users understanding this error message because "model type" isn't as obvious to new users. Maybe we say this operation has called PreserveResponseContent and will provide the stream as part of its response type? Then they can quickly search for PreserveResponseContent in the docs and we have a chance to make them read a few sentences and see some examples.

throw CreateException();
}

public override bool CanRead => throw CreateException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - maybe do this for all the methods too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think others would eventually call into one of these ones

_response?.Dispose();
}

private class ResponseShouldNotBeUsedStream: Stream
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to modify Response.ContentStream's getter so you see the error as soon as you touch it instead of creating a Stream that you might hand off somewhere else for processing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response is abstract so every transport would have to implement this. Not sure if we want to go in that direction.

@@ -440,6 +440,7 @@ directive:
transform: >
$.get.responses["200"]["x-az-response-name"] = "FlattenedDownloadProperties";
$.get.responses["200"]["x-az-public"] = false;
$.get.responses["200"]["x-az-stream"] = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - it's probably good to put this on the 206 response as well because if the order ever gets shuffled, it'd be good if any success type that gets merged together has the flag set.

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

Successfully merging this pull request may close these issues.

Consider making the Message an ultimate exchange type for the pipeline
3 participants