Skip to content

Commit e2d6ffa

Browse files
authored
skip create httpClient only for websocket SkipNegotiation and httpVersion is not http2
1 parent d5ff6c0 commit e2d6ffa

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/SignalR/clients/csharp/Http.Connections.Client/src/HttpConnection.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ public HttpConnection(HttpConnectionOptions httpConnectionOptions, ILoggerFactor
148148

149149
_url = _httpConnectionOptions.Url;
150150

151-
if (!httpConnectionOptions.SkipNegotiation || httpConnectionOptions.Transports != HttpTransportType.WebSockets)
152-
{
153-
_httpClient = CreateHttpClient();
154-
}
151+
_httpClient = CreateHttpClient();
155152

156153
if (httpConnectionOptions.Transports == HttpTransportType.ServerSentEvents && OperatingSystem.IsBrowser())
157154
{
@@ -550,8 +547,17 @@ private async Task StartTransport(Uri connectUrl, HttpTransportType transportTyp
550547
Log.TransportStarted(_logger, transportType);
551548
}
552549

553-
private HttpClient CreateHttpClient()
550+
private HttpClient? CreateHttpClient()
554551
{
552+
var clientWebSocketOptions = _httpConnectionOptions.WebSocketConfiguration(new ClientWebSocketOptions());
553+
if (httpConnectionOptions.SkipNegotiation
554+
&& httpConnectionOptions.Transports == HttpTransportType.WebSockets
555+
&& clientWebSocketOptions.HttpVersion < HttpVersion.Version20
556+
)
557+
{
558+
return null;
559+
}
560+
555561
var httpClientHandler = new HttpClientHandler();
556562
HttpMessageHandler httpMessageHandler = httpClientHandler;
557563

0 commit comments

Comments
 (0)