Modified a few for SetUser method

This commit is contained in:
sta 2014-11-20 11:44:30 +09:00
parent f4f50de125
commit 55527ef514
2 changed files with 9 additions and 8 deletions

View File

@ -115,8 +115,9 @@ namespace WebSocketSharp.Net
return true;
var req = context.Request;
var authRes = req.Headers["Authorization"];
if (schm == AuthenticationSchemes.Basic) {
var authRes = req.Headers["Authorization"];
if (authRes == null || !authRes.StartsWith ("basic", StringComparison.OrdinalIgnoreCase)) {
context.Response.CloseWithAuthChallenge (
AuthenticationChallenge.CreateBasicChallenge (listener.Realm).ToBasicString ());
@ -125,7 +126,6 @@ namespace WebSocketSharp.Net
}
}
else if (schm == AuthenticationSchemes.Digest) {
var authRes = req.Headers["Authorization"];
if (authRes == null || !authRes.StartsWith ("digest", StringComparison.OrdinalIgnoreCase)) {
context.Response.CloseWithAuthChallenge (
AuthenticationChallenge.CreateDigestChallenge (listener.Realm).ToDigestString ());
@ -139,7 +139,7 @@ namespace WebSocketSharp.Net
}
var realm = listener.Realm;
context.SetUser (schm, realm, listener.UserCredentialsFinder);
context.SetUser (authRes, schm, realm, listener.UserCredentialsFinder);
if (req.IsAuthenticated)
return true;

View File

@ -44,8 +44,8 @@ using WebSocketSharp.Net.WebSockets;
namespace WebSocketSharp.Net
{
/// <summary>
/// Provides a set of methods and properties used to access the HTTP request and response
/// information used by the <see cref="HttpListener"/>.
/// Provides the access to the HTTP request and response information
/// used by the <see cref="HttpListener"/>.
/// </summary>
/// <remarks>
/// The HttpListenerContext class cannot be inherited.
@ -160,15 +160,16 @@ namespace WebSocketSharp.Net
#region Internal Methods
internal void SetUser (
string response,
AuthenticationSchemes scheme,
string realm,
Func<IIdentity, NetworkCredential> credentialsFinder)
{
var authRes = AuthenticationResponse.Parse (_request.Headers ["Authorization"]);
if (authRes == null)
var res = AuthenticationResponse.Parse (response);
if (res == null)
return;
var id = authRes.ToIdentity ();
var id = res.ToIdentity ();
if (id == null)
return;