Skip to content

Commit 2152f07

Browse files
committed
rewrite culture handling
1 parent fb1dc77 commit 2152f07

File tree

23 files changed

+91
-93
lines changed

23 files changed

+91
-93
lines changed

src/Microsoft.Azure.SignalR.AspNet/Middleware/NegotiateMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private Task ProcessNegotiationRequest(IOwinContext owinContext, HostContext con
160160
// add OriginalPath and QueryString when the clients protocol is higher than 2.0, earlier ASP.NET SignalR clients does not support redirect URL with query parameters
161161
if (!string.IsNullOrEmpty(clientProtocol) && Version.TryParse(clientProtocol, out var version) && version >= ClientSupportQueryStringVersion)
162162
{
163-
var clientRequestId = _connectionRequestIdProvider.GetRequestId();
163+
var clientRequestId = _connectionRequestIdProvider.GetRequestId("aspnet");
164164
if (clientRequestId != null)
165165
{
166166
// remove system preserved query strings

src/Microsoft.Azure.SignalR.Common/Auth/AuthUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public static string GenerateAccessToken(byte[] keyBytes,
6565
return jwtToken.Length > MaxTokenLength ? throw new AzureSignalRAccessTokenTooLongException() : jwtToken;
6666
}
6767

68-
public static string GenerateRequestId()
68+
public static string GenerateRequestId(string traceIdentifier)
6969
{
70-
return Convert.ToBase64String(BitConverter.GetBytes(Stopwatch.GetTimestamp()));
70+
return $"{traceIdentifier}-{Convert.ToBase64String(BitConverter.GetBytes(Stopwatch.GetTimestamp()))}";
7171
}
7272
}

src/Microsoft.Azure.SignalR.Common/Constants.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ public static class QueryParameter
112112
public const string OriginalPath = "asrs.op";
113113

114114
public const string ConnectionRequestId = "asrs_request_id";
115-
116-
public const string RequestCulture = "asrs_lang";
117-
118-
public const string RequestUICulture = "asrs_ui_lang";
119115
}
120116

121117
public static class CustomizedPingTimer

src/Microsoft.Azure.SignalR.Common/DefaultCultureFeatureManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ private record RequestCultureFeatureWithTimestamp(IRequestCultureFeature Feature
5555
{
5656
}
5757
}
58-
#endif
58+
#endif

src/Microsoft.Azure.SignalR.Common/Interfaces/IClientConnectionManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Collections.Generic;
5+
using System.Globalization;
56
using System.Threading.Tasks;
67

78
namespace Microsoft.Azure.SignalR;

src/Microsoft.Azure.SignalR.Common/Interfaces/IConnectionRequestIdProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace Microsoft.Azure.SignalR;
55

66
internal interface IConnectionRequestIdProvider
77
{
8-
string GetRequestId();
8+
string GetRequestId(string traceIdentifier);
99
}
1010

1111
internal class DefaultConnectionRequestIdProvider : IConnectionRequestIdProvider
1212
{
13-
public string GetRequestId()
13+
public string GetRequestId(string traceIdentifier)
1414
{
15-
return AuthUtility.GenerateRequestId();
15+
return AuthUtility.GenerateRequestId(traceIdentifier);
1616
}
1717
}

src/Microsoft.Azure.SignalR.Common/Interfaces/ICultureFeatureManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ internal interface ICultureFeatureManager
1515

1616
public void Cleanup();
1717
}
18-
#endif
18+
#endif

src/Microsoft.Azure.SignalR.Common/Microsoft.Azure.SignalR.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net462;</TargetFrameworks>
1010
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1111
</PropertyGroup>
12-
12+
1313
<ItemGroup>
1414
<ProjectReference Include="..\Microsoft.Azure.SignalR.Protocols\Microsoft.Azure.SignalR.Protocols.csproj" />
1515
</ItemGroup>

src/Microsoft.Azure.SignalR/ClientConnections/ClientConnectionContext.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ public bool AbortOnClose
140140

141141
private CancellationToken OutgoingAborted => _abortOutgoingCts.Token;
142142

143+
public string RequestId { get; set; }
144+
143145
public ClientConnectionContext(OpenConnectionMessage serviceMessage,
144146
Action<HttpContext> configureContext = null,
145147
PipeOptions transportPipeOptions = null,
@@ -492,22 +494,17 @@ internal void ClearBufferedMessages()
492494
_bufferedMessages.Clear();
493495
}
494496

495-
private static void ProcessQuery(string queryString, out string originalPath)
497+
private void ProcessQuery(string queryString, out string originalPath)
496498
{
497499
originalPath = string.Empty;
498500
var query = QueryHelpers.ParseNullableQuery(queryString);
499501
if (query == null)
500502
{
501503
return;
502504
}
503-
504-
if (query.TryGetValue(Constants.QueryParameter.RequestCulture, out var culture))
505-
{
506-
SetCurrentThreadCulture(culture.FirstOrDefault());
507-
}
508-
if (query.TryGetValue(Constants.QueryParameter.RequestUICulture, out var uiCulture))
505+
if (query.TryGetValue(Constants.QueryParameter.ConnectionRequestId, out var connectionRequestId))
509506
{
510-
SetCurrentThreadUiCulture(uiCulture.FirstOrDefault());
507+
RequestId = connectionRequestId;
511508
}
512509
if (query.TryGetValue(Constants.QueryParameter.OriginalPath, out var path))
513510
{

src/Microsoft.Azure.SignalR/DependencyInjectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private static ISignalRServerBuilder AddAzureSignalRCore(this ISignalRServerBuil
100100
.AddSingleton(typeof(IServerNameProvider), typeof(DefaultServerNameProvider))
101101
.AddSingleton(typeof(IBlazorDetector), typeof(DefaultBlazorDetector))
102102
.AddSingleton(typeof(IConnectionFactory), typeof(ConnectionFactory))
103+
.AddSingleton(typeof(ICultureFeatureManager), typeof(DefaultCultureFeatureManager))
103104
.AddSingleton(typeof(ServiceHubDispatcher<>))
104105
.AddSingleton(typeof(ServerLifetimeManager))
105106
.AddSingleton(typeof(AzureSignalRMarkerService))

0 commit comments

Comments
 (0)