From 9aa51c9bb19a94202801e83a18b450a1525c45da Mon Sep 17 00:00:00 2001 From: Jie Zong Date: Wed, 21 Jan 2026 11:42:07 +0800 Subject: [PATCH 1/2] enable add accepts while buinding requests --- .../Utilities/RestClient.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs b/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs index 866aa34a4..639137569 100644 --- a/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs +++ b/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs @@ -55,7 +55,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 +73,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 +81,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, + string? 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 +108,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 +176,15 @@ private async Task SendAsyncCore( HubMessage? body, Type? typeHint, Func>? handleExpectedResponseAsync = null, + string? 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(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(accepts)); + } try { using var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); From 5305df6afe35b8b6acddcefca49a74ff11902aa6 Mon Sep 17 00:00:00 2001 From: Jie Zong Date: Wed, 21 Jan 2026 14:00:06 +0800 Subject: [PATCH 2/2] refine to use strong type --- src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs b/src/Microsoft.Azure.SignalR.Common/Utilities/RestClient.cs index 639137569..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; @@ -93,7 +94,7 @@ public Task SendMessageWithRetryAsync( string methodName, object?[] args, Func>? handleExpectedResponse = null, - string? accepts = null, + MediaTypeWithQualityHeaderValue? accepts = null, CancellationToken cancellationToken = default) { return SendAsyncCore(Constants.HttpClientNames.MessageResilient, api, httpMethod, new InvocationMessage(methodName, args), null, handleExpectedResponse, accepts, cancellationToken); @@ -176,14 +177,14 @@ private async Task SendAsyncCore( HubMessage? body, Type? typeHint, Func>? handleExpectedResponseAsync = null, - string? accepts = 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(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(accepts)); + request.Headers.Accept.Add(accepts); } try {