diff --git a/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs b/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs index 866aa34a4..7610c61c9 100644 --- a/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs +++ b/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -55,7 +56,7 @@ public Task SendAsync( Func>? handleExpectedResponseAsync, CancellationToken cancellationToken = default) { - return SendAsyncCore(Constants.HttpClientNames.UserDefault, api, httpMethod, null, null, handleExpectedResponseAsync, cancellationToken); + return SendAsyncCore(Constants.HttpClientNames.UserDefault, api, httpMethod, null, null, handleExpectedResponseAsync, null, cancellationToken); } public Task SendWithRetryAsync( @@ -73,7 +74,7 @@ public Task SendWithRetryAsync( Func>? handleExpectedResponseAsync = null, CancellationToken cancellationToken = default) { - return SendAsyncCore(Constants.HttpClientNames.Resilient, api, httpMethod, null, null, handleExpectedResponseAsync, cancellationToken); + return SendAsyncCore(Constants.HttpClientNames.Resilient, api, httpMethod, null, null, handleExpectedResponseAsync, null, cancellationToken); } public Task SendMessageWithRetryAsync( @@ -81,10 +82,22 @@ public Task SendMessageWithRetryAsync( HttpMethod httpMethod, string methodName, object?[] args, - Func? handleExpectedResponse = null, + Func>? handleExpectedResponse = null, CancellationToken cancellationToken = default) { - return SendAsyncCore(Constants.HttpClientNames.MessageResilient, api, httpMethod, new InvocationMessage(methodName, args), null, AsAsync(handleExpectedResponse), cancellationToken); + return SendAsyncCore(Constants.HttpClientNames.MessageResilient, api, httpMethod, new InvocationMessage(methodName, args), null, handleExpectedResponse, null, cancellationToken); + } + + public Task SendMessageWithRetryAsync( + RestApiEndpoint api, + HttpMethod httpMethod, + string methodName, + object?[] args, + Func>? handleExpectedResponse = null, + MediaTypeWithQualityHeaderValue? accepts = null, + CancellationToken cancellationToken = default) + { + return SendAsyncCore(Constants.HttpClientNames.MessageResilient, api, httpMethod, new InvocationMessage(methodName, args), null, handleExpectedResponse, accepts, cancellationToken); } public Task SendStreamMessageWithRetryAsync( @@ -96,7 +109,7 @@ public Task SendStreamMessageWithRetryAsync( Func? handleExpectedResponse = null, CancellationToken cancellationToken = default) { - return SendAsyncCore(Constants.HttpClientNames.MessageResilient, api, httpMethod, new StreamItemMessage(streamId, arg), typeHint, AsAsync(handleExpectedResponse), cancellationToken); + return SendAsyncCore(Constants.HttpClientNames.MessageResilient, api, httpMethod, new StreamItemMessage(streamId, arg), typeHint, AsAsync(handleExpectedResponse), null, cancellationToken); } private static Uri GetUri(string url, IDictionary? query) @@ -164,11 +177,15 @@ private async Task SendAsyncCore( HubMessage? body, Type? typeHint, Func>? handleExpectedResponseAsync = null, + MediaTypeWithQualityHeaderValue? accepts = null, CancellationToken cancellationToken = default) { using var httpClient = _httpClientFactory.CreateClient(httpClientName); using var request = BuildRequest(api, httpMethod, body, typeHint); - + if (accepts != null) + { + request.Headers.Accept.Add(accepts); + } try { using var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);