Skip to content

Commit 091b45c

Browse files
committed
Fix a few for TcpListenerWebSocketContext.cs
1 parent 4125e4d commit 091b45c

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

websocket-sharp/Ext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ internal static string GetValueInternal (this string nameAndValue, string separa
510510
}
511511

512512
internal static TcpListenerWebSocketContext GetWebSocketContext (
513-
this TcpClient client, string protocol, X509Certificate cert, bool secure, Logger logger)
513+
this TcpClient client, string protocol, bool secure, X509Certificate cert, Logger logger)
514514
{
515-
return new TcpListenerWebSocketContext (client, protocol, cert, secure, logger);
515+
return new TcpListenerWebSocketContext (client, protocol, secure, cert, logger);
516516
}
517517

518518
internal static bool IsCompressionExtension (this string value)

websocket-sharp/Net/WebSockets/TcpListenerWebSocketContext.cs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ public class TcpListenerWebSocketContext : WebSocketContext
5959
#region Internal Constructors
6060

6161
internal TcpListenerWebSocketContext (
62-
TcpClient client, string protocol, X509Certificate cert, bool secure, Logger logger)
62+
TcpClient client, string protocol, bool secure, X509Certificate cert, Logger logger)
6363
{
6464
_client = client;
6565
_secure = secure;
66-
_stream = WsStream.CreateServerStream (client, cert, secure);
67-
_request = _stream.ReadHandshake<HandshakeRequest> (
68-
HandshakeRequest.Parse, 90000);
69-
66+
_stream = WsStream.CreateServerStream (client, secure, cert);
67+
_request = _stream.ReadHandshake<HandshakeRequest> (HandshakeRequest.Parse, 90000);
7068
_websocket = new WebSocket (this, protocol, logger);
7169
}
7270

@@ -326,8 +324,8 @@ private Uri createRequestUri ()
326324
var host = _request.Headers ["Host"];
327325
var rawUri = _request.RequestUri;
328326
var path = rawUri.IsAbsoluteUri
329-
? rawUri.PathAndQuery
330-
: HttpUtility.UrlDecode (_request.RawUrl);
327+
? rawUri.PathAndQuery
328+
: HttpUtility.UrlDecode (_request.RawUrl);
331329

332330
return String.Format ("{0}://{1}{2}", scheme, host, path).ToUri ();
333331
}
@@ -356,37 +354,37 @@ internal void SendAuthChallenge (string challenge)
356354
}
357355

358356
internal void SetUser (
359-
AuthenticationSchemes expectedScheme,
357+
AuthenticationSchemes scheme,
360358
string realm,
361359
Func<IIdentity, NetworkCredential> credentialsFinder)
362360
{
363361
var authRes = _request.AuthResponse;
364362
if (authRes == null)
365363
return;
366364

367-
var identity = authRes.ToIdentity ();
368-
if (identity == null)
365+
var id = authRes.ToIdentity ();
366+
if (id == null)
369367
return;
370368

371-
NetworkCredential credentials = null;
369+
NetworkCredential cred = null;
372370
try {
373-
credentials = credentialsFinder (identity);
371+
cred = credentialsFinder (id);
374372
}
375373
catch {
376374
}
377375

378-
if (credentials == null)
376+
if (cred == null)
379377
return;
380378

381-
var valid = expectedScheme == AuthenticationSchemes.Basic
382-
? ((HttpBasicIdentity) identity).Password == credentials.Password
383-
: expectedScheme == AuthenticationSchemes.Digest
384-
? ((HttpDigestIdentity) identity).IsValid (
385-
credentials.Password, realm, _request.HttpMethod, null)
386-
: false;
379+
var valid = scheme == AuthenticationSchemes.Basic
380+
? ((HttpBasicIdentity) id).Password == cred.Password
381+
: scheme == AuthenticationSchemes.Digest
382+
? ((HttpDigestIdentity) id).IsValid (
383+
cred.Password, realm, _request.HttpMethod, null)
384+
: false;
387385

388386
if (valid)
389-
_user = new GenericPrincipal (identity, credentials.Roles);
387+
_user = new GenericPrincipal (id, cred.Roles);
390388
}
391389

392390
#endregion

websocket-sharp/Server/WebSocketServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private void acceptRequestAsync (TcpClient client)
476476
ThreadPool.QueueUserWorkItem (
477477
state => {
478478
try {
479-
var context = client.GetWebSocketContext (null, _cert, _secure, _logger);
479+
var context = client.GetWebSocketContext (null, _secure, _cert, _logger);
480480
if (_authSchemes != AuthenticationSchemes.Anonymous &&
481481
!authenticateRequest (_authSchemes, context))
482482
return;

websocket-sharp/WsStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ internal static WsStream CreateClientStream (
163163
}
164164

165165
internal static WsStream CreateServerStream (
166-
TcpClient client, X509Certificate cert, bool secure)
166+
TcpClient client, bool secure, X509Certificate cert)
167167
{
168168
var netStream = client.GetStream ();
169169
if (secure) {

0 commit comments

Comments
 (0)