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

Update methods #2486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public static class GrpcWebApplicationBuilderExtensions
/// </summary>
/// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IApplicationBuilder UseGrpcWeb(this IApplicationBuilder builder)
{
return builder.UseGrpcWeb(new GrpcWebOptions());
}
public static IApplicationBuilder UseGrpcWeb(this IApplicationBuilder builder) => builder.UseGrpcWeb(new GrpcWebOptions());

/// <summary>
/// Adds gRPC-Web middleware to the specified <see cref="IApplicationBuilder"/>.
Expand Down
13 changes: 3 additions & 10 deletions src/Grpc.Auth/GoogleAuthInterceptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public static AsyncAuthInterceptor FromCredential(ITokenAccess credential)
/// <param name="credential">The credential to use to obtain access tokens.</param>
/// <returns>The interceptor.</returns>
public static AsyncAuthInterceptor FromCredential(ITokenAccessWithHeaders credential)
{
return new AsyncAuthInterceptor(async (context, metadata) =>
=> new AsyncAuthInterceptor(async (context, metadata) =>
{
AccessTokenWithHeaders tokenAndHeaders = await credential.GetAccessTokenWithHeadersForRequestAsync(context.ServiceUrl, CancellationToken.None).ConfigureAwait(false);
metadata.Add(CreateBearerTokenHeader(tokenAndHeaders.AccessToken));
Expand All @@ -71,7 +70,6 @@ public static AsyncAuthInterceptor FromCredential(ITokenAccessWithHeaders creden
}
}
});
}

/// <summary>
/// Creates an <see cref="AsyncAuthInterceptor"/> that will use given access token as authorization.
Expand All @@ -89,15 +87,10 @@ public static AsyncAuthInterceptor FromAccessToken(string accessToken)
}

private static Metadata.Entry CreateBearerTokenHeader(string accessToken)
{
return new Metadata.Entry(AuthorizationHeader, Schema + " " + accessToken);
}
=> new Metadata.Entry(AuthorizationHeader, Schema + " " + accessToken);

/// <summary>
/// Framework independent equivalent of <c>Task.CompletedTask</c>.
/// </summary>
private static Task GetCompletedTask()
{
return Task.CompletedTask;
}
private static Task GetCompletedTask() => Task.CompletedTask;
}
12 changes: 3 additions & 9 deletions src/Grpc.Auth/GoogleGrpcCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public static async Task<ChannelCredentials> GetApplicationDefaultAsync()
/// <param name="accessToken">OAuth2 access token.</param>
/// <returns>The <c>CallCredentials</c> instance.</returns>
public static CallCredentials FromAccessToken(string accessToken)
{
return CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromAccessToken(accessToken));
}
=> CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromAccessToken(accessToken));

/// <summary>
/// Converts a <c>ITokenAccess</c> (e.g. <c>GoogleCredential</c>) object
Expand All @@ -62,9 +60,7 @@ public static CallCredentials FromAccessToken(string accessToken)
/// <param name="credential">The credential to use to obtain access tokens.</param>
/// <returns>The <c>CallCredentials</c> instance.</returns>
public static CallCredentials ToCallCredentials(this ITokenAccess credential)
{
return CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromCredential(credential));
}
=> CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromCredential(credential));

/// <summary>
/// Converts a <c>ITokenAccess</c> (e.g. <c>GoogleCredential</c>) object
Expand All @@ -74,7 +70,5 @@ public static CallCredentials ToCallCredentials(this ITokenAccess credential)
/// <param name="googleCredential">The credential to use to obtain access tokens.</param>
/// <returns>>The <c>ChannelCredentials</c> instance.</returns>
public static ChannelCredentials ToChannelCredentials(this ITokenAccess googleCredential)
{
return ChannelCredentials.Create(new SslCredentials(), googleCredential.ToCallCredentials());
}
=> ChannelCredentials.Create(new SslCredentials(), googleCredential.ToCallCredentials());
}
15 changes: 3 additions & 12 deletions src/Grpc.Core.Api/AsyncAuthInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,15 @@ public AuthInterceptorContext(string serviceUrl, string methodName, Cancellation
/// <summary>
/// The fully qualified service URL for the RPC being called.
/// </summary>
public string ServiceUrl
{
get { return serviceUrl; }
}
public string ServiceUrl => serviceUrl;

/// <summary>
/// The method name of the RPC being called.
/// </summary>
public string MethodName
{
get { return methodName; }
}
public string MethodName => methodName;

/// <summary>
/// The cancellation token of the RPC being called.
/// </summary>
public CancellationToken CancellationToken
{
get { return cancellationToken; }
}
public CancellationToken CancellationToken => cancellationToken;
}
57 changes: 10 additions & 47 deletions src/Grpc.Core.Api/AsyncClientStreamingCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,45 +84,24 @@ public AsyncClientStreamingCall(IClientStreamWriter<TRequest> requestStream,
/// <summary>
/// Asynchronous call result.
/// </summary>
public Task<TResponse> ResponseAsync
{
get
{
return this.responseAsync;
}
}
public Task<TResponse> ResponseAsync => this.responseAsync;

/// <summary>
/// Asynchronous access to response headers.
/// </summary>
public Task<Metadata> ResponseHeadersAsync
{
get
{
return callState.ResponseHeadersAsync();
}
}
public Task<Metadata> ResponseHeadersAsync => callState.ResponseHeadersAsync();

/// <summary>
/// Async stream to send streaming requests.
/// </summary>
public IClientStreamWriter<TRequest> RequestStream
{
get
{
return requestStream;
}
}
public IClientStreamWriter<TRequest> RequestStream => requestStream;

/// <summary>
/// Gets an awaiter used to await this <see cref="AsyncClientStreamingCall{TRequest,TResponse}"/>.
/// </summary>
/// <returns>An awaiter instance.</returns>
/// <remarks>This method is intended for compiler use rather than use directly in code.</remarks>
public TaskAwaiter<TResponse> GetAwaiter()
{
return responseAsync.GetAwaiter();
}
public TaskAwaiter<TResponse> GetAwaiter() => responseAsync.GetAwaiter();

/// <summary>
/// Configures an awaiter used to await this <see cref="AsyncClientStreamingCall{TRequest,TResponse}"/>.
Expand All @@ -132,27 +111,19 @@ public TaskAwaiter<TResponse> GetAwaiter()
/// </param>
/// <returns>An object used to await this task.</returns>
public ConfiguredTaskAwaitable<TResponse> ConfigureAwait(bool continueOnCapturedContext)
{
return responseAsync.ConfigureAwait(continueOnCapturedContext);
}
=> responseAsync.ConfigureAwait(continueOnCapturedContext);

/// <summary>
/// Gets the call status if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Status GetStatus()
{
return callState.GetStatus();
}
public Status GetStatus() => callState.GetStatus();

/// <summary>
/// Gets the call trailing metadata if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Metadata GetTrailers()
{
return callState.GetTrailers();
}
public Metadata GetTrailers() => callState.GetTrailers();

/// <summary>
/// Provides means to cleanup after the call.
Expand All @@ -164,21 +135,13 @@ public Metadata GetTrailers()
/// Normally, there is no need for you to dispose the call unless you want to utilize the
/// "Cancel" semantics of invoking <c>Dispose</c>.
/// </remarks>
public void Dispose()
{
callState.Dispose();
}
public void Dispose() => callState.Dispose();

private string DebuggerToString() => CallDebuggerHelpers.DebuggerToString(callState);

private sealed class AsyncClientStreamingCallDebugView
private sealed class AsyncClientStreamingCallDebugView(AsyncClientStreamingCall<TRequest, TResponse> call)
{
private readonly AsyncClientStreamingCall<TRequest, TResponse> _call;

public AsyncClientStreamingCallDebugView(AsyncClientStreamingCall<TRequest, TResponse> call)
{
_call = call;
}
private readonly AsyncClientStreamingCall<TRequest, TResponse> _call = call;

public bool IsComplete => CallDebuggerHelpers.GetStatus(_call.callState) != null;
public Status? Status => CallDebuggerHelpers.GetStatus(_call.callState);
Expand Down
48 changes: 8 additions & 40 deletions src/Grpc.Core.Api/AsyncDuplexStreamingCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,53 +83,29 @@ public AsyncDuplexStreamingCall(IClientStreamWriter<TRequest> requestStream,
/// <summary>
/// Async stream to read streaming responses.
/// </summary>
public IAsyncStreamReader<TResponse> ResponseStream
{
get
{
return responseStream;
}
}
public IAsyncStreamReader<TResponse> ResponseStream => responseStream;

/// <summary>
/// Async stream to send streaming requests.
/// </summary>
public IClientStreamWriter<TRequest> RequestStream
{
get
{
return requestStream;
}
}
public IClientStreamWriter<TRequest> RequestStream => requestStream;

/// <summary>
/// Asynchronous access to response headers.
/// </summary>
public Task<Metadata> ResponseHeadersAsync
{
get
{
return callState.ResponseHeadersAsync();
}
}
public Task<Metadata> ResponseHeadersAsync => callState.ResponseHeadersAsync();

/// <summary>
/// Gets the call status if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Status GetStatus()
{
return callState.GetStatus();
}
public Status GetStatus() => callState.GetStatus();

/// <summary>
/// Gets the call trailing metadata if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Metadata GetTrailers()
{
return callState.GetTrailers();
}
public Metadata GetTrailers() => callState.GetTrailers();

/// <summary>
/// Provides means to cleanup after the call.
Expand All @@ -141,21 +117,13 @@ public Metadata GetTrailers()
/// Normally, there is no need for you to dispose the call unless you want to utilize the
/// "Cancel" semantics of invoking <c>Dispose</c>.
/// </remarks>
public void Dispose()
{
callState.Dispose();
}
public void Dispose() => callState.Dispose();

private string DebuggerToString() => CallDebuggerHelpers.DebuggerToString(callState);

private sealed class AsyncDuplexStreamingCallDebugView
private sealed class AsyncDuplexStreamingCallDebugView(AsyncDuplexStreamingCall<TRequest, TResponse> call)
{
private readonly AsyncDuplexStreamingCall<TRequest, TResponse> _call;

public AsyncDuplexStreamingCallDebugView(AsyncDuplexStreamingCall<TRequest, TResponse> call)
{
_call = call;
}
private readonly AsyncDuplexStreamingCall<TRequest, TResponse> _call = call;

public bool IsComplete => CallDebuggerHelpers.GetStatus(_call.callState) != null;
public Status? Status => CallDebuggerHelpers.GetStatus(_call.callState);
Expand Down
40 changes: 7 additions & 33 deletions src/Grpc.Core.Api/AsyncServerStreamingCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,24 @@ public AsyncServerStreamingCall(IAsyncStreamReader<TResponse> responseStream,
/// <summary>
/// Async stream to read streaming responses.
/// </summary>
public IAsyncStreamReader<TResponse> ResponseStream
{
get
{
return responseStream;
}
}
public IAsyncStreamReader<TResponse> ResponseStream => responseStream;

/// <summary>
/// Asynchronous access to response headers.
/// </summary>
public Task<Metadata> ResponseHeadersAsync
{
get
{
return callState.ResponseHeadersAsync();
}
}
public Task<Metadata> ResponseHeadersAsync => callState.ResponseHeadersAsync();

/// <summary>
/// Gets the call status if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Status GetStatus()
{
return callState.GetStatus();
}
public Status GetStatus() => callState.GetStatus();

/// <summary>
/// Gets the call trailing metadata if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Metadata GetTrailers()
{
return callState.GetTrailers();
}
public Metadata GetTrailers() => callState.GetTrailers();

/// <summary>
/// Provides means to cleanup after the call.
Expand All @@ -122,21 +104,13 @@ public Metadata GetTrailers()
/// Normally, there is no need for you to dispose the call unless you want to utilize the
/// "Cancel" semantics of invoking <c>Dispose</c>.
/// </remarks>
public void Dispose()
{
callState.Dispose();
}
public void Dispose() => callState.Dispose();

private string DebuggerToString() => CallDebuggerHelpers.DebuggerToString(callState);

private sealed class AsyncServerStreamingCallDebugView
private sealed class AsyncServerStreamingCallDebugView(AsyncServerStreamingCall<TResponse> call)
{
private readonly AsyncServerStreamingCall<TResponse> _call;

public AsyncServerStreamingCallDebugView(AsyncServerStreamingCall<TResponse> call)
{
_call = call;
}
private readonly AsyncServerStreamingCall<TResponse> _call = call;

public bool IsComplete => CallDebuggerHelpers.GetStatus(_call.callState) != null;
public Status? Status => CallDebuggerHelpers.GetStatus(_call.callState);
Expand Down
Loading