@@ -24,6 +24,7 @@ internal partial class WebSocketsTransport : ITransport
24
24
private readonly ILogger _logger ;
25
25
private readonly TimeSpan _closeTimeout ;
26
26
private volatile bool _aborted ;
27
+ private bool _isRunningInBrowser ;
27
28
28
29
private IDuplexPipe _transport ;
29
30
@@ -88,6 +89,8 @@ public WebSocketsTransport(HttpConnectionOptions httpConnectionOptions, ILoggerF
88
89
89
90
// Ignore the HttpConnectionOptions access token provider. We were given an updated delegate from the HttpConnection.
90
91
_accessTokenProvider = accessTokenProvider ;
92
+
93
+ _isRunningInBrowser = Utils . IsRunningInBrowser ( ) ;
91
94
}
92
95
93
96
public async Task StartAsync ( Uri url , TransferFormat transferFormat , CancellationToken cancellationToken = default )
@@ -114,14 +117,12 @@ public async Task StartAsync(Uri url, TransferFormat transferFormat, Cancellatio
114
117
var accessToken = await _accessTokenProvider ( ) ;
115
118
if ( ! string . IsNullOrEmpty ( accessToken ) )
116
119
{
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 )
119
122
{
120
123
var accessTokenEncoded = UrlEncoder . Default . Encode ( accessToken ) ;
121
124
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 ) ;
125
126
}
126
127
else
127
128
{
0 commit comments