Removed WebSocketStream.cs
This commit is contained in:
@@ -40,24 +40,19 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using WebSocketSharp.Net.Security;
|
||||
|
||||
namespace WebSocketSharp.Net
|
||||
{
|
||||
internal sealed class HttpConnection
|
||||
{
|
||||
#region Private Const Fields
|
||||
|
||||
private const int _bufferSize = 8192;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private byte [] _buffer;
|
||||
private byte[] _buffer;
|
||||
private const int _bufferSize = 8192;
|
||||
private bool _chunked;
|
||||
private HttpListenerContext _context;
|
||||
private bool _contextWasBound;
|
||||
@@ -78,7 +73,6 @@ namespace WebSocketSharp.Net
|
||||
private object _sync;
|
||||
private int _timeout;
|
||||
private Timer _timer;
|
||||
private WebSocketStream _websocketStream;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -205,7 +199,6 @@ namespace WebSocketSharp.Net
|
||||
|
||||
_inputStream = null;
|
||||
_outputStream = null;
|
||||
_websocketStream = null;
|
||||
|
||||
_stream.Dispose ();
|
||||
_stream = null;
|
||||
@@ -317,7 +310,7 @@ namespace WebSocketSharp.Net
|
||||
|
||||
// true -> Done processing.
|
||||
// false -> Need more input.
|
||||
private bool processInput (byte [] data)
|
||||
private bool processInput (byte[] data)
|
||||
{
|
||||
var len = data.Length;
|
||||
var used = 0;
|
||||
@@ -359,7 +352,7 @@ namespace WebSocketSharp.Net
|
||||
return false;
|
||||
}
|
||||
|
||||
private string readLine (byte [] buffer, int offset, int length, ref int used)
|
||||
private string readLine (byte[] buffer, int offset, int length, ref int used)
|
||||
{
|
||||
if (_currentLine == null)
|
||||
_currentLine = new StringBuilder ();
|
||||
@@ -368,7 +361,7 @@ namespace WebSocketSharp.Net
|
||||
used = 0;
|
||||
for (int i = offset; i < last && _lineState != LineState.LF; i++) {
|
||||
used++;
|
||||
var b = buffer [i];
|
||||
var b = buffer[i];
|
||||
if (b == 13)
|
||||
_lineState = LineState.CR;
|
||||
else if (b == 10)
|
||||
@@ -447,7 +440,7 @@ namespace WebSocketSharp.Net
|
||||
public void BeginReadRequest ()
|
||||
{
|
||||
if (_buffer == null)
|
||||
_buffer = new byte [_bufferSize];
|
||||
_buffer = new byte[_bufferSize];
|
||||
|
||||
if (_reuses == 1)
|
||||
_timeout = 15000;
|
||||
@@ -512,20 +505,6 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
}
|
||||
|
||||
public WebSocketStream GetWebSocketStream ()
|
||||
{
|
||||
if (_websocketStream != null || _socket == null)
|
||||
return _websocketStream;
|
||||
|
||||
lock (_sync) {
|
||||
if (_socket == null)
|
||||
return _websocketStream;
|
||||
|
||||
_websocketStream = new WebSocketStream (_stream, _secure);
|
||||
return _websocketStream;
|
||||
}
|
||||
}
|
||||
|
||||
public void SendError ()
|
||||
{
|
||||
SendError (_context.ErrorMessage, _context.ErrorStatus);
|
||||
|
@@ -1,82 +0,0 @@
|
||||
#region License
|
||||
/*
|
||||
* SslStream.cs
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2012-2014 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
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* 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
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace WebSocketSharp.Net.Security
|
||||
{
|
||||
internal class SslStream : System.Net.Security.SslStream
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public SslStream (NetworkStream innerStream)
|
||||
: base (innerStream)
|
||||
{
|
||||
}
|
||||
|
||||
public SslStream (NetworkStream innerStream, bool leaveInnerStreamOpen)
|
||||
: base (innerStream, leaveInnerStreamOpen)
|
||||
{
|
||||
}
|
||||
|
||||
public SslStream (
|
||||
NetworkStream innerStream,
|
||||
bool leaveInnerStreamOpen,
|
||||
RemoteCertificateValidationCallback userCertificateValidationCallback)
|
||||
: base (innerStream, leaveInnerStreamOpen, userCertificateValidationCallback)
|
||||
{
|
||||
}
|
||||
|
||||
public SslStream (
|
||||
NetworkStream innerStream,
|
||||
bool leaveInnerStreamOpen,
|
||||
RemoteCertificateValidationCallback userCertificateValidationCallback,
|
||||
LocalCertificateSelectionCallback userCertificateSelectionCallback)
|
||||
: base (
|
||||
innerStream,
|
||||
leaveInnerStreamOpen,
|
||||
userCertificateValidationCallback,
|
||||
userCertificateSelectionCallback)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public bool DataAvailable {
|
||||
get {
|
||||
return ((NetworkStream) InnerStream).DataAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -29,6 +29,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace WebSocketSharp.Net.WebSockets
|
||||
@@ -37,8 +38,6 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// Provides the properties used to access the information in a WebSocket connection request
|
||||
/// received by the <see cref="HttpListener"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// </remarks>
|
||||
public class HttpListenerWebSocketContext : WebSocketContext
|
||||
{
|
||||
#region Private Fields
|
||||
@@ -61,9 +60,9 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
|
||||
#region Internal Properties
|
||||
|
||||
internal WebSocketStream Stream {
|
||||
internal Stream Stream {
|
||||
get {
|
||||
return _context.Connection.GetWebSocketStream ();
|
||||
return _context.Connection.Stream;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// </value>
|
||||
public override string Host {
|
||||
get {
|
||||
return _context.Request.Headers ["Host"];
|
||||
return _context.Request.Headers["Host"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +162,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// </value>
|
||||
public override string Origin {
|
||||
get {
|
||||
return _context.Request.Headers ["Origin"];
|
||||
return _context.Request.Headers["Origin"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +202,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// </value>
|
||||
public override string SecWebSocketKey {
|
||||
get {
|
||||
return _context.Request.Headers ["Sec-WebSocket-Key"];
|
||||
return _context.Request.Headers["Sec-WebSocket-Key"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +219,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// </value>
|
||||
public override IEnumerable<string> SecWebSocketProtocols {
|
||||
get {
|
||||
var protocols = _context.Request.Headers ["Sec-WebSocket-Protocol"];
|
||||
var protocols = _context.Request.Headers["Sec-WebSocket-Protocol"];
|
||||
if (protocols != null)
|
||||
foreach (var protocol in protocols.Split (','))
|
||||
yield return protocol.Trim ();
|
||||
@@ -238,7 +237,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
/// </value>
|
||||
public override string SecWebSocketVersion {
|
||||
get {
|
||||
return _context.Request.Headers ["Sec-WebSocket-Version"];
|
||||
return _context.Request.Headers["Sec-WebSocket-Version"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -29,6 +29,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Security.Principal;
|
||||
@@ -48,7 +50,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
private NameValueCollection _queryString;
|
||||
private HttpRequest _request;
|
||||
private bool _secure;
|
||||
private WebSocketStream _stream;
|
||||
private Stream _stream;
|
||||
private TcpClient _tcpClient;
|
||||
private Uri _uri;
|
||||
private IPrincipal _user;
|
||||
@@ -63,8 +65,18 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
{
|
||||
_tcpClient = tcpClient;
|
||||
_secure = secure;
|
||||
_stream = WebSocketStream.CreateServerStream (tcpClient, secure, certificate);
|
||||
_request = _stream.ReadHttpRequest (90000);
|
||||
|
||||
var netStream = tcpClient.GetStream ();
|
||||
if (secure) {
|
||||
var sslStream = new SslStream (netStream, false);
|
||||
sslStream.AuthenticateAsServer (certificate);
|
||||
_stream = sslStream;
|
||||
}
|
||||
else {
|
||||
_stream = netStream;
|
||||
}
|
||||
|
||||
_request = HttpRequest.Read (_stream, 90000);
|
||||
_uri = HttpUtility.CreateRequestUrl (
|
||||
_request.RequestUri, _request.Headers["Host"], _request.IsWebSocketRequest, secure);
|
||||
|
||||
@@ -75,7 +87,7 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
|
||||
#region Internal Properties
|
||||
|
||||
internal WebSocketStream Stream {
|
||||
internal Stream Stream {
|
||||
get {
|
||||
return _stream;
|
||||
}
|
||||
@@ -324,8 +336,9 @@ namespace WebSocketSharp.Net.WebSockets
|
||||
|
||||
internal void SendAuthenticationChallenge (string challenge)
|
||||
{
|
||||
_stream.WriteBytes (HttpResponse.CreateUnauthorizedResponse (challenge).ToByteArray ());
|
||||
_request = _stream.ReadHttpRequest (15000);
|
||||
var buff = HttpResponse.CreateUnauthorizedResponse (challenge).ToByteArray ();
|
||||
_stream.Write (buff, 0, buff.Length);
|
||||
_request = HttpRequest.Read (_stream, 15000);
|
||||
}
|
||||
|
||||
internal void SetUser (
|
||||
|
Reference in New Issue
Block a user