@@ -78,36 +78,13 @@ protected internal override async Task OnOpenAsync(TimeSpan timeout)
78
78
79
79
try
80
80
{
81
- //old implementation:
82
- //var clientWebSocket = new ClientWebSocket();
83
- //await ConfigureClientWebSocketAsync(clientWebSocket, helper.RemainingTime());
84
- //await clientWebSocket.ConnectAsync(Via, await helper.GetCancellationTokenAsync());
85
- //ValidateWebSocketConnection(clientWebSocket);
86
- //WebSocket = clientWebSocket;
87
-
88
- /* new implementation:
89
- 1. Create a SocketsHttpHandler, set certificate, certificate validation callback, and credentials. Wrap in an HttpMessageInvoker.
90
- 2. Create an HttpRequestMessage. Set the required WebSocket headers, including any sub protocols, set the service url etc.
91
- 3. Send the request using the invoker
92
- 4. Validate the response headers, including upgrade status code, websocket specific headers, sub protocol.
93
- 5. Fetch the content stream from the response content
94
- 6. Wrap the content stream in a websocket
95
- */
96
-
97
81
try
98
82
{
99
83
while ( true )
100
84
{
101
85
try
102
86
{
103
87
HttpRequestMessage request = new HttpRequestMessage ( HttpMethod . Get , Via ) { Version = HttpVersion . Version11 } ;
104
- //if (options._requestHeaders?.Count > 0) // use field to avoid lazily initializing the collection
105
- //{
106
- // foreach (string key in options.RequestHeaders)
107
- // {
108
- // request.Headers.TryAddWithoutValidation(key, options.RequestHeaders[key]);
109
- // }
110
- //}
111
88
112
89
// These headers were added for WCF specific handshake to avoid encoder or transfermode mismatch between client and server.
113
90
// For BinaryMessageEncoder, since we are using a sessionful channel for websocket, the encoder is actually different when
@@ -320,7 +297,7 @@ private static void ValidateHeader(HttpHeaders headers, string name, string expe
320
297
SecurityTokenContainer clientCertificateToken = null ;
321
298
if ( _channelFactory is HttpsChannelFactory < IDuplexSessionChannel > httpsChannelFactory )
322
299
{
323
- if ( httpsChannelFactory . RequireClientCertificate )
300
+ if ( httpsChannelFactory . RequireClientCertificate )
324
301
{
325
302
SecurityTokenProvider certificateProvider = await httpsChannelFactory . CreateAndOpenCertificateTokenProviderAsync ( RemoteAddress , Via , channelParameterCollection , helper . RemainingTime ( ) ) ;
326
303
clientCertificateToken = await httpsChannelFactory . GetCertificateSecurityTokenAsync ( certificateProvider , RemoteAddress , Via , channelParameterCollection , helper ) ;
@@ -334,7 +311,7 @@ private static void ValidateHeader(HttpHeaders headers, string name, string expe
334
311
} ;
335
312
}
336
313
}
337
-
314
+ //Fix for issue #5729: Removed the httpsChannelFactory.RequireClientCertificate condition from the following if statement.
338
315
if ( httpsChannelFactory . WebSocketCertificateCallback != null )
339
316
{
340
317
handler . SslOptions . RemoteCertificateValidationCallback = httpsChannelFactory . WebSocketCertificateCallback ;
@@ -343,7 +320,7 @@ private static void ValidateHeader(HttpHeaders headers, string name, string expe
343
320
344
321
//configure handler.Proxy
345
322
( NetworkCredential credential , TokenImpersonationLevel impersonationLevel , AuthenticationLevel authenticationLevel ) =
346
- await HttpChannelUtilities . GetCredentialAsync ( _channelFactory . AuthenticationScheme , _webRequestTokenProvider , timeout ) ;
323
+ await HttpChannelUtilities . GetCredentialAsync ( _channelFactory . AuthenticationScheme , _webRequestTokenProvider , timeout ) ;
347
324
if ( _channelFactory . Proxy != null )
348
325
{
349
326
handler . Proxy = _channelFactory . Proxy ;
@@ -418,7 +395,7 @@ private string AddWebSocketHeaders(HttpRequestMessage request)
418
395
{
419
396
request . Headers . TryAddWithoutValidation ( HttpKnownHeaderNames . SecWebSocketProtocol , WebSocketSettings . SubProtocol ) ;
420
397
}
421
-
398
+
422
399
return secValue ;
423
400
}
424
401
@@ -502,4 +479,3 @@ private void CleanupTokenProviders()
502
479
}
503
480
}
504
481
}
505
-
0 commit comments