-
Notifications
You must be signed in to change notification settings - Fork 101
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
Rewrite culture handling logic #2068
base: dev
Are you sure you want to change the base?
Conversation
d0e4d1d
to
7b20491
Compare
@@ -160,7 +160,7 @@ private Task ProcessNegotiationRequest(IOwinContext owinContext, HostContext con | |||
// 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 | |||
if (!string.IsNullOrEmpty(clientProtocol) && Version.TryParse(clientProtocol, out var version) && version >= ClientSupportQueryStringVersion) | |||
{ | |||
var clientRequestId = _connectionRequestIdProvider.GetRequestId(); | |||
var clientRequestId = _connectionRequestIdProvider.GetRequestId(""); |
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.
so for aspnet the id always start with -
?
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.
use a prefix "aspnet"
@@ -149,6 +154,12 @@ protected override Task OnClientConnectedAsync(OpenConnectionMessage message) | |||
connection.ServiceConnection = this; | |||
|
|||
connection.Features.Set<IConnectionMigrationFeature>(null); | |||
|
|||
if (!_cultureInfoManager.TryApplyCulture(connection.RequestId)) |
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.
if (_cultureInfoManager.TryGetCultureFeature(connection.RequestId, out var feature)){
connection.GetHttpContext().Features.Set<IRequestCultureFeature>(feature)
}
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.
connection.GetHttpContext().Features.Set<IRequestCultureFeature>(feature)
doesn't take effect
I use CultureInfo.CurrentCulture=XXX
and CultureInfo.CureentUICulture=XXX
7972e63
to
2152f07
Compare
{ | ||
return Convert.ToBase64String(BitConverter.GetBytes(Stopwatch.GetTimestamp())); | ||
return $"{traceIdentifier}-{Convert.ToBase64String(BitConverter.GetBytes(Stopwatch.GetTimestamp()))}"; |
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.
traceIdentifier is in such format 0HN7T92QVLV5T:00000009
https://github.com/aspnet/KestrelHttpServer/blob/master/src/Kestrel.Core/Internal/Infrastructure/CorrelationIdGenerator.cs#L19, and could be customized using middlewares.
Do we want :
in the requestId? might the generated requestId too long?
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.
now I use return $"{traceIdentifier}:{Stopwatch.GetTimestamp().ToString("X")}";
base64 encoding is not needed for this id will be UrlEncoded before inserted into query string
use hex to shorten the length
src/Microsoft.Azure.SignalR.Common/Interfaces/IClientConnectionManager.cs
Outdated
Show resolved
Hide resolved
); | ||
|
||
_cultureInfoManager.TryAddCultureFeature(clientRequestId, cultureFeature); |
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.
is it possible to check if culture feature is unchanged? If it is unchanged, there is no need to add and apply
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.
is it that only blazor app is impacted by the culture?
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.
1\ yes, we can check. However if we don't add the feature, a not found error log will be triggered when trying to apply the culture feature.
2\ added blazor check
8fd466e
to
47b8960
Compare
e48755d
to
9983800
Compare
3f24099
to
aaad24b
Compare
Add some UTs? |
{ | ||
return Convert.ToBase64String(BitConverter.GetBytes(Stopwatch.GetTimestamp())); | ||
// Before filled into query string, this id will be process by "WebUtility.UrlEncode(...)". So base64 encoding is not needed. |
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.
let's replace :
with -
to make it more readable, also use string.IsNullorEmpty(traceidentifier) ? {Stopwatch.GetTimestamp().ToString("X") : $"{traceIdentifier}:{Stopwatch.GetTimestamp().ToString("X")}"
instead of append aspnet
prefix
public bool IsDefaultFeature(IRequestCultureFeature feature) | ||
{ | ||
// this is the default feature value in blazor when no culture feature is configured by app server | ||
return feature.RequestCulture.Culture == CultureInfo.DefaultThreadCurrentCulture && feature.RequestCulture.UICulture == CultureInfo.DefaultThreadCurrentUICulture && feature.Provider is AcceptLanguageHeaderRequestCultureProvider; |
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.
is AcceptLanguageHeaderRequestCultureProvider does not mean it is default though
Based on #2067
Fix #2038