Fix for HTTP auth

This commit is contained in:
sta 2014-01-27 15:39:27 +09:00
parent a2713c4df2
commit 3970e9917d
4 changed files with 15 additions and 13 deletions

View File

@ -30,9 +30,9 @@ namespace Example2
wssv.AuthenticationSchemes = AuthenticationSchemes.Basic; wssv.AuthenticationSchemes = AuthenticationSchemes.Basic;
wssv.Realm = "WebSocket Test"; wssv.Realm = "WebSocket Test";
wssv.UserCredentialsFinder = identity => { wssv.UserCredentialsFinder = identity => {
var name = identity.Name; var expected = "nobita";
return name == "nobita" return identity.Name == expected
? new NetworkCredential (name, "password") ? new NetworkCredential (expected, "password", "gunfighter")
: null; : null;
}; };
*/ */

View File

@ -30,9 +30,9 @@ namespace Example3
_httpsv.AuthenticationSchemes = AuthenticationSchemes.Basic; _httpsv.AuthenticationSchemes = AuthenticationSchemes.Basic;
_httpsv.Realm = "WebSocket Test"; _httpsv.Realm = "WebSocket Test";
_httpsv.UserCredentialsFinder = identity => { _httpsv.UserCredentialsFinder = identity => {
var name = identity.Name; var expected = "nobita";
return name == "nobita" return identity.Name == expected
? new NetworkCredential (name, "password") ? new NetworkCredential (expected, "password", "gunfighter")
: null; : null;
}; };
*/ */

View File

@ -64,7 +64,8 @@ namespace WebSocketSharp.Net.WebSockets
_client = client; _client = client;
_secure = secure; _secure = secure;
_stream = WsStream.CreateServerStream (client, cert, secure); _stream = WsStream.CreateServerStream (client, cert, secure);
_request = _stream.ReadHandshakeRequest (); _request = _stream.ReadHandshake<HandshakeRequest> (
HandshakeRequest.Parse, 90000);
_websocket = new WebSocket (this, logger); _websocket = new WebSocket (this, logger);
} }
@ -365,7 +366,8 @@ namespace WebSocketSharp.Net.WebSockets
var res = new HandshakeResponse (HttpStatusCode.Unauthorized); var res = new HandshakeResponse (HttpStatusCode.Unauthorized);
res.Headers ["WWW-Authenticate"] = challenge; res.Headers ["WWW-Authenticate"] = challenge;
_stream.WriteHandshake (res); _stream.WriteHandshake (res);
_request = _stream.ReadHandshakeRequest (); _request = _stream.ReadHandshake<HandshakeRequest> (
HandshakeRequest.Parse, 15000);
} }
internal void SetUser ( internal void SetUser (

View File

@ -43,7 +43,6 @@ namespace WebSocketSharp
#region Private Const Fields #region Private Const Fields
private const int _handshakeHeadersLimitLen = 8192; private const int _handshakeHeadersLimitLen = 8192;
private const int _handshakeTimeout = 90000;
#endregion #endregion
@ -183,7 +182,8 @@ namespace WebSocketSharp
return new WsStream (conn.Stream, conn.IsSecure); return new WsStream (conn.Stream, conn.IsSecure);
} }
internal T ReadHandshake<T> (Func<string [], T> parser) internal T ReadHandshake<T> (
Func<string [], T> parser, int millisecondsTimeout)
where T : HandshakeBase where T : HandshakeBase
{ {
var timeout = false; var timeout = false;
@ -193,7 +193,7 @@ namespace WebSocketSharp
_innerStream.Close (); _innerStream.Close ();
}, },
null, null,
_handshakeTimeout, millisecondsTimeout,
-1); -1);
T handshake = null; T handshake = null;
@ -265,12 +265,12 @@ namespace WebSocketSharp
public HandshakeRequest ReadHandshakeRequest () public HandshakeRequest ReadHandshakeRequest ()
{ {
return ReadHandshake<HandshakeRequest> (HandshakeRequest.Parse); return ReadHandshake<HandshakeRequest> (HandshakeRequest.Parse, 90000);
} }
public HandshakeResponse ReadHandshakeResponse () public HandshakeResponse ReadHandshakeResponse ()
{ {
return ReadHandshake<HandshakeResponse> (HandshakeResponse.Parse); return ReadHandshake<HandshakeResponse> (HandshakeResponse.Parse, 90000);
} }
public bool WriteFrame (WsFrame frame) public bool WriteFrame (WsFrame frame)