Fix for HTTP Basic/Digest Authentication
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2012-2013 sta.blockhead
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@@ -34,7 +34,8 @@ using System.Security.Principal;
|
||||
namespace WebSocketSharp.Net.WebSockets
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the WebSocket connection request objects received by the <see cref="HttpListener"/>.
|
||||
/// Provides access to the WebSocket connection request information received by
|
||||
/// the <see cref="HttpListener"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
@@ -50,11 +51,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
|
||||
#region Internal Constructors
|
||||
|
||||
internal HttpListenerWebSocketContext (HttpListenerContext context)
|
||||
internal HttpListenerWebSocketContext (
|
||||
HttpListenerContext context, Logger logger)
|
||||
{
|
||||
_context = context;
|
||||
_stream = WsStream.CreateServerStream (context);
|
||||
_websocket = new WebSocket (this);
|
||||
_websocket = new WebSocket (this, logger ?? new Logger ());
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -72,10 +74,11 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cookies used in the WebSocket opening handshake.
|
||||
/// Gets the cookies used in the WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="WebSocketSharp.Net.CookieCollection"/> that contains the cookies.
|
||||
/// A <see cref="WebSocketSharp.Net.CookieCollection"/> that contains the
|
||||
/// cookies.
|
||||
/// </value>
|
||||
public override CookieCollection CookieCollection {
|
||||
get {
|
||||
@@ -84,10 +87,10 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP headers used in the WebSocket opening handshake.
|
||||
/// Gets the HTTP headers used in the WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Collections.Specialized.NameValueCollection"/> that contains the HTTP headers.
|
||||
/// A <see cref="NameValueCollection"/> that contains the HTTP headers.
|
||||
/// </value>
|
||||
public override NameValueCollection Headers {
|
||||
get {
|
||||
@@ -96,10 +99,11 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Host header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Host header field used in the WebSocket connection
|
||||
/// request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Host header field.
|
||||
/// A <see cref="string"/> that represents the value of the Host header field.
|
||||
/// </value>
|
||||
public override string Host {
|
||||
get {
|
||||
@@ -120,10 +124,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the client connected from the local computer.
|
||||
/// Gets a value indicating whether the client connected from the local
|
||||
/// computer.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the client connected from the local computer; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the client connected from the local computer; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public override bool IsLocal {
|
||||
get {
|
||||
@@ -135,7 +141,8 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets a value indicating whether the WebSocket connection is secured.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the WebSocket connection is secured; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the WebSocket connection is secured; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public override bool IsSecureConnection {
|
||||
get {
|
||||
@@ -144,10 +151,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the request is a WebSocket connection request.
|
||||
/// Gets a value indicating whether the request is a WebSocket connection
|
||||
/// request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the request is a WebSocket connection request; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the request is a WebSocket connection request; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public override bool IsWebSocketRequest {
|
||||
get {
|
||||
@@ -156,10 +165,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Origin header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Origin header field used in the WebSocket
|
||||
/// connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Origin header field.
|
||||
/// A <see cref="string"/> that represents the value of the Origin header
|
||||
/// field.
|
||||
/// </value>
|
||||
public override string Origin {
|
||||
get {
|
||||
@@ -171,19 +182,22 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the absolute path of the requested WebSocket URI.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the absolute path of the requested WebSocket URI.
|
||||
/// A <see cref="string"/> that represents the absolute path of the requested
|
||||
/// WebSocket URI.
|
||||
/// </value>
|
||||
public override string Path {
|
||||
get {
|
||||
return RequestUri.GetAbsolutePath ();
|
||||
return _context.Request.Url.GetAbsolutePath ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of query string variables used in the WebSocket opening handshake.
|
||||
/// Gets the collection of query string variables used in the WebSocket
|
||||
/// connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables.
|
||||
/// A <see cref="NameValueCollection"/> that contains the collection of query
|
||||
/// string variables.
|
||||
/// </value>
|
||||
public override NameValueCollection QueryString {
|
||||
get {
|
||||
@@ -195,22 +209,26 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the WebSocket URI requested by the client.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="Uri"/> that contains the WebSocket URI.
|
||||
/// A <see cref="Uri"/> that represents the WebSocket URI requested by the
|
||||
/// client.
|
||||
/// </value>
|
||||
public override Uri RequestUri {
|
||||
get {
|
||||
return _context.Request.RawUrl.ToUri ();
|
||||
return _context.Request.Url;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Sec-WebSocket-Key header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Sec-WebSocket-Key header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketKey property provides a part of the information used by the server to prove that it received a valid WebSocket opening handshake.
|
||||
/// This property provides a part of the information used by the server to
|
||||
/// prove that it received a valid WebSocket connection request.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Sec-WebSocket-Key header field.
|
||||
/// A <see cref="string"/> that represents the value of the Sec-WebSocket-Key
|
||||
/// header field.
|
||||
/// </value>
|
||||
public override string SecWebSocketKey {
|
||||
get {
|
||||
@@ -219,13 +237,15 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the values of the Sec-WebSocket-Protocol header field used in the WebSocket opening handshake.
|
||||
/// Gets the values of the Sec-WebSocket-Protocol header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketProtocols property indicates the subprotocols of the WebSocket connection.
|
||||
/// This property represents the subprotocols of the WebSocket connection.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// An IEnumerable<string> that contains the values of the Sec-WebSocket-Protocol header field.
|
||||
/// An IEnumerable<string> that contains the values of the
|
||||
/// Sec-WebSocket-Protocol header field.
|
||||
/// </value>
|
||||
public override IEnumerable<string> SecWebSocketProtocols {
|
||||
get {
|
||||
@@ -234,13 +254,15 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Sec-WebSocket-Version header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Sec-WebSocket-Version header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketVersion property indicates the WebSocket protocol version of the connection.
|
||||
/// This property represents the WebSocket protocol version of the connection.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Sec-WebSocket-Version header field.
|
||||
/// A <see cref="string"/> that represents the value of the
|
||||
/// Sec-WebSocket-Version header field.
|
||||
/// </value>
|
||||
public override string SecWebSocketVersion {
|
||||
get {
|
||||
@@ -252,7 +274,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the server endpoint as an IP address and a port number.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that contains the server endpoint.
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that represents the server endpoint.
|
||||
/// </value>
|
||||
public override System.Net.IPEndPoint ServerEndPoint {
|
||||
get {
|
||||
@@ -261,10 +283,11 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the client information (identity, authentication information and security roles).
|
||||
/// Gets the client information (identity, authentication information and
|
||||
/// security roles).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="IPrincipal"/> that contains the client information.
|
||||
/// A <see cref="IPrincipal"/> that represents the client information.
|
||||
/// </value>
|
||||
public override IPrincipal User {
|
||||
get {
|
||||
@@ -276,7 +299,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the client endpoint as an IP address and a port number.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that contains the client endpoint.
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that represents the client endpoint.
|
||||
/// </value>
|
||||
public override System.Net.IPEndPoint UserEndPoint {
|
||||
get {
|
||||
@@ -285,7 +308,8 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebSocket instance used for two-way communication between client and server.
|
||||
/// Gets the WebSocket instance used for two-way communication between client
|
||||
/// and server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="WebSocketSharp.WebSocket"/>.
|
||||
@@ -305,15 +329,22 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
_context.Connection.Close (true);
|
||||
}
|
||||
|
||||
internal void Close (HttpStatusCode code)
|
||||
{
|
||||
_context.Response.Close (code);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="string"/> that represents the current <see cref="HttpListenerWebSocketContext"/>.
|
||||
/// Returns a <see cref="string"/> that represents the current
|
||||
/// <see cref="HttpListenerWebSocketContext"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="string"/> that represents the current <see cref="HttpListenerWebSocketContext"/>.
|
||||
/// A <see cref="string"/> that represents the current
|
||||
/// <see cref="HttpListenerWebSocketContext"/>.
|
||||
/// </returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2012-2013 sta.blockhead
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@@ -36,7 +36,8 @@ using System.Security.Principal;
|
||||
namespace WebSocketSharp.Net.WebSockets
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the WebSocket connection request objects received by the <see cref="TcpListener"/>.
|
||||
/// Provides access to the WebSocket connection request information received by
|
||||
/// the <see cref="TcpListener"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
@@ -49,19 +50,22 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
private HandshakeRequest _request;
|
||||
private bool _secure;
|
||||
private WsStream _stream;
|
||||
private Uri _uri;
|
||||
private IPrincipal _user;
|
||||
private WebSocket _websocket;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Constructors
|
||||
|
||||
internal TcpListenerWebSocketContext (TcpClient client, bool secure, X509Certificate cert)
|
||||
internal TcpListenerWebSocketContext (
|
||||
TcpClient client, X509Certificate cert, bool secure, Logger logger)
|
||||
{
|
||||
_client = client;
|
||||
_secure = secure;
|
||||
_stream = WsStream.CreateServerStream (client, secure, cert);
|
||||
_stream = WsStream.CreateServerStream (client, cert, secure);
|
||||
_request = HandshakeRequest.Parse (_stream.ReadHandshake ());
|
||||
_websocket = new WebSocket (this);
|
||||
_websocket = new WebSocket (this, logger);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -79,25 +83,23 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cookies used in the WebSocket opening handshake.
|
||||
/// Gets the cookies used in the WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="CookieCollection"/> that contains the cookies.
|
||||
/// A <see cref="WebSocketSharp.Net.CookieCollection"/> that contains the
|
||||
/// cookies.
|
||||
/// </value>
|
||||
public override CookieCollection CookieCollection {
|
||||
get {
|
||||
if (_cookies == null)
|
||||
_cookies = _request.Cookies;
|
||||
|
||||
return _cookies;
|
||||
return _cookies ?? (_cookies = _request.Cookies);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP headers used in the WebSocket opening handshake.
|
||||
/// Gets the HTTP headers used in the WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Collections.Specialized.NameValueCollection"/> that contains the HTTP headers.
|
||||
/// A <see cref="NameValueCollection"/> that contains the HTTP headers.
|
||||
/// </value>
|
||||
public override NameValueCollection Headers {
|
||||
get {
|
||||
@@ -106,10 +108,11 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Host header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Host header field used in the WebSocket connection
|
||||
/// request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Host header field.
|
||||
/// A <see cref="string"/> that represents the value of the Host header field.
|
||||
/// </value>
|
||||
public override string Host {
|
||||
get {
|
||||
@@ -123,20 +126,19 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// <value>
|
||||
/// <c>true</c> if the client is authenticated; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
/// <exception cref="NotImplementedException">
|
||||
/// This property is not implemented.
|
||||
/// </exception>
|
||||
public override bool IsAuthenticated {
|
||||
get {
|
||||
throw new NotImplementedException ();
|
||||
return _user != null && _user.Identity.IsAuthenticated;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the client connected from the local computer.
|
||||
/// Gets a value indicating whether the client connected from the local
|
||||
/// computer.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the client connected from the local computer; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the client connected from the local computer; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public override bool IsLocal {
|
||||
get {
|
||||
@@ -148,7 +150,8 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets a value indicating whether the WebSocket connection is secured.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the WebSocket connection is secured; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the WebSocket connection is secured; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public override bool IsSecureConnection {
|
||||
get {
|
||||
@@ -157,10 +160,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the request is a WebSocket connection request.
|
||||
/// Gets a value indicating whether the request is a WebSocket connection
|
||||
/// request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the request is a WebSocket connection request; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the request is a WebSocket connection request; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public override bool IsWebSocketRequest {
|
||||
get {
|
||||
@@ -169,10 +174,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Origin header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Origin header field used in the WebSocket
|
||||
/// connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Origin header field.
|
||||
/// A <see cref="string"/> that represents the value of the Origin header
|
||||
/// field.
|
||||
/// </value>
|
||||
public override string Origin {
|
||||
get {
|
||||
@@ -184,7 +191,8 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the absolute path of the requested WebSocket URI.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the absolute path of the requested WebSocket URI.
|
||||
/// A <see cref="string"/> that represents the absolute path of the requested
|
||||
/// WebSocket URI.
|
||||
/// </value>
|
||||
public override string Path {
|
||||
get {
|
||||
@@ -193,10 +201,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of query string variables used in the WebSocket opening handshake.
|
||||
/// Gets the collection of query string variables used in the WebSocket
|
||||
/// connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables.
|
||||
/// A <see cref="NameValueCollection"/> that contains the collection of query
|
||||
/// string variables.
|
||||
/// </value>
|
||||
public override NameValueCollection QueryString {
|
||||
get {
|
||||
@@ -208,22 +218,26 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the WebSocket URI requested by the client.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="Uri"/> that contains the WebSocket URI.
|
||||
/// A <see cref="Uri"/> that represents the WebSocket URI requested by the
|
||||
/// client.
|
||||
/// </value>
|
||||
public override Uri RequestUri {
|
||||
get {
|
||||
return _request.RequestUri;
|
||||
return _uri ?? (_uri = createRequestUri ());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Sec-WebSocket-Key header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Sec-WebSocket-Key header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketKey property provides a part of the information used by the server to prove that it received a valid WebSocket opening handshake.
|
||||
/// This property provides a part of the information used by the server to
|
||||
/// prove that it received a valid WebSocket connection request.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Sec-WebSocket-Key header field.
|
||||
/// A <see cref="string"/> that represents the value of the Sec-WebSocket-Key
|
||||
/// header field.
|
||||
/// </value>
|
||||
public override string SecWebSocketKey {
|
||||
get {
|
||||
@@ -232,13 +246,15 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the values of the Sec-WebSocket-Protocol header field used in the WebSocket opening handshake.
|
||||
/// Gets the values of the Sec-WebSocket-Protocol header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property indicates the subprotocols of the WebSocket connection.
|
||||
/// This property represents the subprotocols of the WebSocket connection.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// An IEnumerable<string> that contains the values of the Sec-WebSocket-Protocol header field.
|
||||
/// An IEnumerable<string> that contains the values of the
|
||||
/// Sec-WebSocket-Protocol header field.
|
||||
/// </value>
|
||||
public override IEnumerable<string> SecWebSocketProtocols {
|
||||
get {
|
||||
@@ -247,13 +263,15 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Sec-WebSocket-Version header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Sec-WebSocket-Version header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketVersion property indicates the WebSocket protocol version of the connection.
|
||||
/// This property represents the WebSocket protocol version of the connection.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Sec-WebSocket-Version header field.
|
||||
/// A <see cref="string"/> that represents the value of the
|
||||
/// Sec-WebSocket-Version header field.
|
||||
/// </value>
|
||||
public override string SecWebSocketVersion {
|
||||
get {
|
||||
@@ -265,7 +283,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the server endpoint as an IP address and a port number.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that contains the server endpoint.
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that represents the server endpoint.
|
||||
/// </value>
|
||||
public override System.Net.IPEndPoint ServerEndPoint {
|
||||
get {
|
||||
@@ -274,17 +292,15 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the client information (identity, authentication information and security roles).
|
||||
/// Gets the client information (identity, authentication information and
|
||||
/// security roles).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="IPrincipal"/> that contains the client information.
|
||||
/// A <see cref="IPrincipal"/> that represents the client information.
|
||||
/// </value>
|
||||
/// <exception cref="NotImplementedException">
|
||||
/// This property is not implemented.
|
||||
/// </exception>
|
||||
public override IPrincipal User {
|
||||
get {
|
||||
throw new NotImplementedException ();
|
||||
return _user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +308,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the client endpoint as an IP address and a port number.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that contains the client endpoint.
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that represents the client endpoint.
|
||||
/// </value>
|
||||
public override System.Net.IPEndPoint UserEndPoint {
|
||||
get {
|
||||
@@ -301,7 +317,8 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebSocket instance used for two-way communication between client and server.
|
||||
/// Gets the WebSocket instance used for two-way communication between client
|
||||
/// and server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="WebSocketSharp.WebSocket"/>.
|
||||
@@ -314,6 +331,22 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private Uri createRequestUri ()
|
||||
{
|
||||
var scheme = _secure ? "wss" : "ws";
|
||||
var host = _request.Headers ["Host"];
|
||||
var rawUri = _request.RequestUri;
|
||||
var path = rawUri.IsAbsoluteUri
|
||||
? rawUri.PathAndQuery
|
||||
: HttpUtility.UrlDecode (_request.RawUrl);
|
||||
|
||||
return String.Format ("{0}://{1}{2}", scheme, host, path).ToUri ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal void Close ()
|
||||
@@ -322,15 +355,64 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
_client.Close ();
|
||||
}
|
||||
|
||||
internal void Close (HttpStatusCode code)
|
||||
{
|
||||
_websocket.Close (HandshakeResponse.CreateCloseResponse (code));
|
||||
}
|
||||
|
||||
internal void SendAuthChallenge (string challenge)
|
||||
{
|
||||
var res = new HandshakeResponse (HttpStatusCode.Unauthorized);
|
||||
res.Headers ["WWW-Authenticate"] = challenge;
|
||||
_stream.WriteHandshake (res);
|
||||
_request = HandshakeRequest.Parse (_stream.ReadHandshake ());
|
||||
}
|
||||
|
||||
internal void SetUser (
|
||||
AuthenticationSchemes expectedScheme,
|
||||
string realm,
|
||||
Func<IIdentity, NetworkCredential> credentialsFinder)
|
||||
{
|
||||
var authRes = _request.AuthResponse;
|
||||
if (authRes == null)
|
||||
return;
|
||||
|
||||
var identity = authRes.ToIdentity ();
|
||||
if (identity == null)
|
||||
return;
|
||||
|
||||
NetworkCredential credentials = null;
|
||||
try {
|
||||
credentials = credentialsFinder (identity);
|
||||
}
|
||||
catch {
|
||||
}
|
||||
|
||||
if (credentials == null)
|
||||
return;
|
||||
|
||||
var valid = expectedScheme == AuthenticationSchemes.Basic
|
||||
? ((HttpBasicIdentity) identity).Password == credentials.Password
|
||||
: expectedScheme == AuthenticationSchemes.Digest
|
||||
? ((HttpDigestIdentity) identity).IsValid (
|
||||
credentials.Password, realm, _request.HttpMethod, null)
|
||||
: false;
|
||||
|
||||
if (valid)
|
||||
_user = new GenericPrincipal (identity, credentials.Roles);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="string"/> that represents the current <see cref="TcpListenerWebSocketContext"/>.
|
||||
/// Returns a <see cref="string"/> that represents the current
|
||||
/// <see cref="TcpListenerWebSocketContext"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="string"/> that represents the current <see cref="TcpListenerWebSocketContext"/>.
|
||||
/// A <see cref="string"/> that represents the current
|
||||
/// <see cref="TcpListenerWebSocketContext"/>.
|
||||
/// </returns>
|
||||
public override string ToString ()
|
||||
{
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2012-2013 sta.blockhead
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@@ -34,7 +34,7 @@ using System.Security.Principal;
|
||||
namespace WebSocketSharp.Net.WebSockets
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the WebSocket connection request objects.
|
||||
/// Provides access to the WebSocket connection request information.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The WebSocketContext class is an abstract class.
|
||||
@@ -55,26 +55,28 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cookies used in the WebSocket opening handshake.
|
||||
/// Gets the cookies used in the WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="WebSocketSharp.Net.CookieCollection"/> that contains the cookies.
|
||||
/// A <see cref="WebSocketSharp.Net.CookieCollection"/> that contains the
|
||||
/// cookies.
|
||||
/// </value>
|
||||
public abstract CookieCollection CookieCollection { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP headers used in the WebSocket opening handshake.
|
||||
/// Gets the HTTP headers used in the WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Collections.Specialized.NameValueCollection"/> that contains the HTTP headers.
|
||||
/// A <see cref="NameValueCollection"/> that contains the HTTP headers.
|
||||
/// </value>
|
||||
public abstract NameValueCollection Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Host header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Host header field used in the WebSocket connection
|
||||
/// request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Host header field.
|
||||
/// A <see cref="string"/> that represents the value of the Host header field.
|
||||
/// </value>
|
||||
public abstract string Host { get; }
|
||||
|
||||
@@ -87,10 +89,12 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
public abstract bool IsAuthenticated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the client connected from the local computer.
|
||||
/// Gets a value indicating whether the client connected from the local
|
||||
/// computer.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the client connected from the local computer; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the client connected from the local computer; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public abstract bool IsLocal { get; }
|
||||
|
||||
@@ -98,23 +102,28 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets a value indicating whether the WebSocket connection is secured.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the WebSocket connection is secured; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the WebSocket connection is secured; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public abstract bool IsSecureConnection { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the request is a WebSocket connection request.
|
||||
/// Gets a value indicating whether the request is a WebSocket connection
|
||||
/// request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the request is a WebSocket connection request; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the request is a WebSocket connection request; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </value>
|
||||
public abstract bool IsWebSocketRequest { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Origin header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Origin header field used in the WebSocket
|
||||
/// connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Origin header field.
|
||||
/// A <see cref="string"/> that represents the value of the Origin header
|
||||
/// field.
|
||||
/// </value>
|
||||
public abstract string Origin { get; }
|
||||
|
||||
@@ -122,15 +131,18 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the absolute path of the requested WebSocket URI.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the absolute path of the requested WebSocket URI.
|
||||
/// A <see cref="string"/> that represents the absolute path of the requested
|
||||
/// WebSocket URI.
|
||||
/// </value>
|
||||
public abstract string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of query string variables used in the WebSocket opening handshake.
|
||||
/// Gets the collection of query string variables used in the WebSocket
|
||||
/// connection request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables.
|
||||
/// A <see cref="NameValueCollection"/> that contains the collection of query
|
||||
/// string variables.
|
||||
/// </value>
|
||||
public abstract NameValueCollection QueryString { get; }
|
||||
|
||||
@@ -138,40 +150,47 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the WebSocket URI requested by the client.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="Uri"/> that contains the WebSocket URI.
|
||||
/// A <see cref="Uri"/> that represents the WebSocket URI.
|
||||
/// </value>
|
||||
public abstract Uri RequestUri { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Sec-WebSocket-Key header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Sec-WebSocket-Key header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketKey property provides a part of the information used by the server to prove that it received a valid WebSocket opening handshake.
|
||||
/// This property provides a part of the information used by the server to
|
||||
/// prove that it received a valid WebSocket connection request.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Sec-WebSocket-Key header field.
|
||||
/// A <see cref="string"/> that represents the value of the Sec-WebSocket-Key
|
||||
/// header field.
|
||||
/// </value>
|
||||
public abstract string SecWebSocketKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the values of the Sec-WebSocket-Protocol header field used in the WebSocket opening handshake.
|
||||
/// Gets the values of the Sec-WebSocket-Protocol header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketProtocols property indicates the subprotocols of the WebSocket connection.
|
||||
/// This property represents the subprotocols of the WebSocket connection.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// An IEnumerable<string> that contains the values of the Sec-WebSocket-Protocol header field.
|
||||
/// An IEnumerable<string> that contains the values of the
|
||||
/// Sec-WebSocket-Protocol header field.
|
||||
/// </value>
|
||||
public abstract IEnumerable<string> SecWebSocketProtocols { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the Sec-WebSocket-Version header field used in the WebSocket opening handshake.
|
||||
/// Gets the value of the Sec-WebSocket-Version header field used in the
|
||||
/// WebSocket connection request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The SecWebSocketVersion property indicates the WebSocket protocol version of the connection.
|
||||
/// This property represents the WebSocket protocol version of the connection.
|
||||
/// </remarks>
|
||||
/// <value>
|
||||
/// A <see cref="string"/> that contains the value of the Sec-WebSocket-Version header field.
|
||||
/// A <see cref="string"/> that represents the value of the
|
||||
/// Sec-WebSocket-Version header field.
|
||||
/// </value>
|
||||
public abstract string SecWebSocketVersion { get; }
|
||||
|
||||
@@ -179,15 +198,16 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the server endpoint as an IP address and a port number.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that contains the server endpoint.
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that represents the server endpoint.
|
||||
/// </value>
|
||||
public abstract System.Net.IPEndPoint ServerEndPoint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the client information (identity, authentication information and security roles).
|
||||
/// Gets the client information (identity, authentication information and
|
||||
/// security roles).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="IPrincipal"/> that contains the client information.
|
||||
/// A <see cref="IPrincipal"/> that represents the client information.
|
||||
/// </value>
|
||||
public abstract IPrincipal User { get; }
|
||||
|
||||
@@ -195,12 +215,13 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Gets the client endpoint as an IP address and a port number.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that contains the client endpoint.
|
||||
/// A <see cref="System.Net.IPEndPoint"/> that represents the client endpoint.
|
||||
/// </value>
|
||||
public abstract System.Net.IPEndPoint UserEndPoint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebSocket instance used for two-way communication between client and server.
|
||||
/// Gets the WebSocket instance used for two-way communication between client
|
||||
/// and server.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="WebSocketSharp.WebSocket"/>.
|
||||
|
Reference in New Issue
Block a user