Skip to content

Commit e70e52d

Browse files
committed
Respond to feedback
1 parent e0af487 commit e70e52d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal static Uri AppendQueryString(Uri url, string qs)
4343
return builder.Uri;
4444
}
4545

46-
internal static bool IsRunningBlazorWasm()
46+
internal static bool IsRunningInBrowser()
4747
{
4848
return RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY"));
4949
}

src/SignalR/clients/csharp/Http.Connections.Client/src/Internal/WebSocketsTransport.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal partial class WebSocketsTransport : ITransport
2424
private readonly ILogger _logger;
2525
private readonly TimeSpan _closeTimeout;
2626
private volatile bool _aborted;
27+
private bool _isRunningInBrowser;
2728

2829
private IDuplexPipe _transport;
2930

@@ -88,6 +89,8 @@ public WebSocketsTransport(HttpConnectionOptions httpConnectionOptions, ILoggerF
8889

8990
// Ignore the HttpConnectionOptions access token provider. We were given an updated delegate from the HttpConnection.
9091
_accessTokenProvider = accessTokenProvider;
92+
93+
_isRunningInBrowser = Utils.IsRunningInBrowser();
9194
}
9295

9396
public async Task StartAsync(Uri url, TransferFormat transferFormat, CancellationToken cancellationToken = default)
@@ -114,14 +117,12 @@ public async Task StartAsync(Uri url, TransferFormat transferFormat, Cancellatio
114117
var accessToken = await _accessTokenProvider();
115118
if (!string.IsNullOrEmpty(accessToken))
116119
{
117-
// We can't use request headers in the browser, so instead append the token as a query string if running WASM
118-
if (Utils.IsRunningBlazorWasm())
120+
// We can't use request headers in the browser, so instead append the token as a query string in that case
121+
if (_isRunningInBrowser)
119122
{
120123
var accessTokenEncoded = UrlEncoder.Default.Encode(accessToken);
121124
accessTokenEncoded = "access_token=" + accessTokenEncoded;
122-
var builder = new UriBuilder(resolvedUrl);
123-
builder.Query += builder.Query.Length == 0 ? ("?" + accessTokenEncoded) : ("&" + accessTokenEncoded);
124-
resolvedUrl = builder.Uri;
125+
resolvedUrl = Utils.AppendQueryString(resolvedUrl, accessTokenEncoded);
125126
}
126127
else
127128
{

0 commit comments

Comments
 (0)