Fix due to the modified WebSocketContext.cs

This commit is contained in:
sta
2013-02-26 11:39:59 +09:00
parent 8232c95cd8
commit 2e8a24a667
93 changed files with 1016 additions and 362 deletions

View File

@@ -43,8 +43,8 @@ namespace WebSocketSharp.Net.WebSockets {
#region Fields
private HttpListenerContext _context;
private WebSocket _socket;
private WsStream _stream;
private WebSocket _websocket;
private WsStream _wsStream;
#endregion
@@ -52,24 +52,18 @@ namespace WebSocketSharp.Net.WebSockets {
internal HttpListenerWebSocketContext(HttpListenerContext context)
{
_context = context;
_stream = WsStream.CreateServerStream(context);
_socket = new WebSocket(this);
_context = context;
_wsStream = WsStream.CreateServerStream(context);
_websocket = new WebSocket(this);
}
#endregion
#region Internal Properties
internal HttpListenerContext BaseContext {
get {
return _context;
}
}
#region Internal Property
internal WsStream Stream {
get {
return _stream;
return _wsStream;
}
}
@@ -137,6 +131,22 @@ namespace WebSocketSharp.Net.WebSockets {
}
}
/// <summary>
/// Gets a value indicating whether the WebSocket connection request is valid.
/// </summary>
/// <value>
/// <c>true</c> if the WebSocket connection request is valid; otherwise, <c>false</c>.
/// </value>
public override bool IsValid {
get {
return !_context.Request.IsWebSocketRequest
? false
: SecWebSocketKey.IsNullOrEmpty()
? false
: !SecWebSocketVersion.IsNullOrEmpty();
}
}
/// <summary>
/// Gets the value of the Origin header field used in the WebSocket opening handshake.
/// </summary>
@@ -161,6 +171,18 @@ namespace WebSocketSharp.Net.WebSockets {
}
}
/// <summary>
/// Gets the collection of query string variables used in the WebSocket opening handshake.
/// </summary>
/// <value>
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables.
/// </value>
public override NameValueCollection QueryString {
get {
return _context.Request.QueryString;
}
}
/// <summary>
/// Gets the WebSocket URI requested by the client.
/// </summary>
@@ -262,10 +284,19 @@ namespace WebSocketSharp.Net.WebSockets {
/// </value>
public override WebSocket WebSocket {
get {
return _socket;
return _websocket;
}
}
#endregion
#region Internal Method
internal void Close()
{
_context.Connection.Close(true);
}
#endregion
}
}

View File

@@ -43,38 +43,32 @@ namespace WebSocketSharp.Net.WebSockets {
{
#region Fields
private TcpClient _client;
private TcpClient _tcpClient;
private bool _isSecure;
private RequestHandshake _request;
private WebSocket _socket;
private WsStream _stream;
private WebSocket _websocket;
private WsStream _wsStream;
#endregion
#region Constructor
internal TcpListenerWebSocketContext(TcpClient client, bool secure)
internal TcpListenerWebSocketContext(TcpClient tcpClient, bool secure)
{
_client = client;
_isSecure = secure;
_stream = WsStream.CreateServerStream(client, secure);
_request = RequestHandshake.Parse(_stream.ReadHandshake());
_socket = new WebSocket(this);
_tcpClient = tcpClient;
_isSecure = secure;
_wsStream = WsStream.CreateServerStream(tcpClient, secure);
_request = RequestHandshake.Parse(_wsStream.ReadHandshake());
_websocket = new WebSocket(this);
}
#endregion
#region Internal Properties
internal TcpClient Client {
get {
return _client;
}
}
internal WsStream Stream {
get {
return _stream;
return _wsStream;
}
}
@@ -130,12 +124,9 @@ namespace WebSocketSharp.Net.WebSockets {
/// <value>
/// <c>true</c> if the client connected from the local computer; otherwise, <c>false</c>.
/// </value>
/// <exception cref="NotImplementedException">
/// This property is not implemented.
/// </exception>
public override bool IsLocal {
get {
throw new NotImplementedException();
return UserEndPoint.Address.IsLocal();
}
}
@@ -151,6 +142,22 @@ namespace WebSocketSharp.Net.WebSockets {
}
}
/// <summary>
/// Gets a value indicating whether the WebSocket connection request is valid.
/// </summary>
/// <value>
/// <c>true</c> if the WebSocket connection request is valid; otherwise, <c>false</c>.
/// </value>
public override bool IsValid {
get {
return !_request.IsWebSocketRequest
? false
: SecWebSocketKey.IsNullOrEmpty()
? false
: !SecWebSocketVersion.IsNullOrEmpty();
}
}
/// <summary>
/// Gets the value of the Origin header field used in the WebSocket opening handshake.
/// </summary>
@@ -175,6 +182,18 @@ namespace WebSocketSharp.Net.WebSockets {
}
}
/// <summary>
/// Gets the collection of query string variables used in the WebSocket opening handshake.
/// </summary>
/// <value>
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables.
/// </value>
public override NameValueCollection QueryString {
get {
return _request.QueryString;
}
}
/// <summary>
/// Gets the WebSocket URI requested by the client.
/// </summary>
@@ -240,7 +259,7 @@ namespace WebSocketSharp.Net.WebSockets {
/// </value>
public virtual System.Net.IPEndPoint ServerEndPoint {
get {
return (System.Net.IPEndPoint)_client.Client.LocalEndPoint;
return (System.Net.IPEndPoint)_tcpClient.Client.LocalEndPoint;
}
}
@@ -267,7 +286,7 @@ namespace WebSocketSharp.Net.WebSockets {
/// </value>
public virtual System.Net.IPEndPoint UserEndPoint {
get {
return (System.Net.IPEndPoint)_client.Client.RemoteEndPoint;
return (System.Net.IPEndPoint)_tcpClient.Client.RemoteEndPoint;
}
}
@@ -279,10 +298,20 @@ namespace WebSocketSharp.Net.WebSockets {
/// </value>
public override WebSocket WebSocket {
get {
return _socket;
return _websocket;
}
}
#endregion
#region Internal Method
internal void Close()
{
_wsStream.Close();
_tcpClient.Close();
}
#endregion
}
}

View File

@@ -94,6 +94,14 @@ namespace WebSocketSharp.Net.WebSockets {
/// </value>
public abstract bool IsSecureConnection { get; }
/// <summary>
/// Gets a value indicating whether the WebSocket connection request is valid.
/// </summary>
/// <value>
/// <c>true</c> if the WebSocket connection request is valid; otherwise, <c>false</c>.
/// </value>
public abstract bool IsValid { get; }
/// <summary>
/// Gets the value of the Origin header field used in the WebSocket opening handshake.
/// </summary>
@@ -102,6 +110,14 @@ namespace WebSocketSharp.Net.WebSockets {
/// </value>
public abstract string Origin { get; }
/// <summary>
/// Gets the collection of query string variables used in the WebSocket opening handshake.
/// </summary>
/// <value>
/// A <see cref="NameValueCollection"/> that contains the collection of query string variables.
/// </value>
public abstract NameValueCollection QueryString { get; }
/// <summary>
/// Gets the WebSocket URI requested by the client.
/// </summary>