-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 sync support to retriable stream #6420
Conversation
} | ||
else | ||
{ | ||
s_eventSource.ResponseContentText(message.Response, responseTextEncoding, message.CancellationToken); |
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.
Why do we need these sync code paths? We are inside an async method.
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.
It's a pattern we use where we write a method that takes a bool async
parameter and becomes fully sync or async depending on the value.
This is a shorter example from BearerTokenAuthenticationPolicy implementation:
public override Task ProcessAsync(HttpPipelineMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline)
{
return ProcessAsync(message, pipeline, true);
}
public override void Process(HttpPipelineMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline)
{
ProcessAsync(message, pipeline, false).EnsureCompleted();
}
public async Task ProcessAsync(HttpPipelineMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline, bool async)
{
>>>> string token = async ?
await _credential.GetTokenAsync(_scopes, message.CancellationToken).ConfigureAwait(false) :
_credential.GetToken(_scopes, message.CancellationToken);
if (token != _currentToken)
{
// Avoid per request allocations
_currentToken = token;
_headerValue = "Bearer " + token;
}
message.Request.SetHeader(HttpHeader.Names.Authorization, _headerValue);
if (async)
{
>>>> await ProcessNextAsync(message, pipeline);
}
else
{
>>>> ProcessNext(message, pipeline);
}
}
Also, adds validating stream that makes sure appropriate methods are being called on the response stream.
Fix bugs found using validating stream.
Breaking change:
Sync request factory is now required.
Before:
After: