Skip to content

Commit 17d0c2a

Browse files
committed
Clean up.
1 parent c75604e commit 17d0c2a

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

src/System.ServiceModel.Http/src/System/ServiceModel/Channels/ClientWebSocketTransportDuplexSessionChannel.cs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,36 +78,13 @@ protected internal override async Task OnOpenAsync(TimeSpan timeout)
7878

7979
try
8080
{
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-
9781
try
9882
{
9983
while (true)
10084
{
10185
try
10286
{
10387
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-
//}
11188

11289
// These headers were added for WCF specific handshake to avoid encoder or transfermode mismatch between client and server.
11390
// 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
320297
SecurityTokenContainer clientCertificateToken = null;
321298
if (_channelFactory is HttpsChannelFactory<IDuplexSessionChannel> httpsChannelFactory)
322299
{
323-
if(httpsChannelFactory.RequireClientCertificate)
300+
if (httpsChannelFactory.RequireClientCertificate)
324301
{
325302
SecurityTokenProvider certificateProvider = await httpsChannelFactory.CreateAndOpenCertificateTokenProviderAsync(RemoteAddress, Via, channelParameterCollection, helper.RemainingTime());
326303
clientCertificateToken = await httpsChannelFactory.GetCertificateSecurityTokenAsync(certificateProvider, RemoteAddress, Via, channelParameterCollection, helper);
@@ -334,7 +311,7 @@ private static void ValidateHeader(HttpHeaders headers, string name, string expe
334311
};
335312
}
336313
}
337-
314+
//Fix for issue #5729: Removed the httpsChannelFactory.RequireClientCertificate condition from the following if statement.
338315
if (httpsChannelFactory.WebSocketCertificateCallback != null)
339316
{
340317
handler.SslOptions.RemoteCertificateValidationCallback = httpsChannelFactory.WebSocketCertificateCallback;
@@ -343,7 +320,7 @@ private static void ValidateHeader(HttpHeaders headers, string name, string expe
343320

344321
//configure handler.Proxy
345322
(NetworkCredential credential, TokenImpersonationLevel impersonationLevel, AuthenticationLevel authenticationLevel) =
346-
await HttpChannelUtilities.GetCredentialAsync(_channelFactory.AuthenticationScheme, _webRequestTokenProvider, timeout);
323+
await HttpChannelUtilities.GetCredentialAsync(_channelFactory.AuthenticationScheme, _webRequestTokenProvider, timeout);
347324
if (_channelFactory.Proxy != null)
348325
{
349326
handler.Proxy = _channelFactory.Proxy;
@@ -418,7 +395,7 @@ private string AddWebSocketHeaders(HttpRequestMessage request)
418395
{
419396
request.Headers.TryAddWithoutValidation(HttpKnownHeaderNames.SecWebSocketProtocol, WebSocketSettings.SubProtocol);
420397
}
421-
398+
422399
return secValue;
423400
}
424401

@@ -502,4 +479,3 @@ private void CleanupTokenProviders()
502479
}
503480
}
504481
}
505-

src/System.ServiceModel.Http/src/System/ServiceModel/Channels/HttpKnownHeaderNames.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace System.ServiceModel.Channels
55
{
6-
// from https://source.dot.net/#System.Net.WebSockets.Client/src/libraries/Common/src/System/Net/HttpKnownHeaderNames.cs
76
internal static partial class HttpKnownHeaderNames
87
{
98
public const string Accept = "Accept";

0 commit comments

Comments
 (0)