Fix a few for WsStream.cs
This commit is contained in:
parent
87d48ed9ad
commit
4611ed7a8d
@ -54,9 +54,9 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Constructors
|
#region Internal Constructors
|
||||||
|
|
||||||
private WsStream (Stream innerStream, bool secure)
|
internal WsStream (Stream innerStream, bool secure)
|
||||||
{
|
{
|
||||||
_innerStream = innerStream;
|
_innerStream = innerStream;
|
||||||
_secure = secure;
|
_secure = secure;
|
||||||
@ -65,14 +65,14 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Internal Constructors
|
#region Public Constructors
|
||||||
|
|
||||||
internal WsStream (NetworkStream innerStream)
|
public WsStream (NetworkStream innerStream)
|
||||||
: this (innerStream, false)
|
: this (innerStream, false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
internal WsStream (SslStream innerStream)
|
public WsStream (SslStream innerStream)
|
||||||
: this (innerStream, true)
|
: this (innerStream, true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -109,10 +109,10 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
private static string [] readHandshakeHeaders (Stream stream)
|
private static string [] readHandshakeHeaders (Stream stream)
|
||||||
{
|
{
|
||||||
var buffer = new List<byte> ();
|
var buff = new List<byte> ();
|
||||||
var count = 0;
|
var count = 0;
|
||||||
Action<int> add = i => {
|
Action<int> add = i => {
|
||||||
buffer.Add ((byte) i);
|
buff.Add ((byte) i);
|
||||||
count++;
|
count++;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -132,56 +132,16 @@ namespace WebSocketSharp
|
|||||||
"The header part of a handshake is greater than the limit length.");
|
"The header part of a handshake is greater than the limit length.");
|
||||||
|
|
||||||
var crlf = "\r\n";
|
var crlf = "\r\n";
|
||||||
return Encoding.UTF8.GetString (buffer.ToArray ())
|
return Encoding.UTF8.GetString (buff.ToArray ())
|
||||||
.Replace (crlf + " ", " ")
|
.Replace (crlf + " ", " ")
|
||||||
.Replace (crlf + "\t", " ")
|
.Replace (crlf + "\t", " ")
|
||||||
.Split (new string [] { crlf }, StringSplitOptions.RemoveEmptyEntries);
|
.Split (new [] { crlf }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Internal Methods
|
#region Internal Methods
|
||||||
|
|
||||||
internal static WsStream CreateClientStream (
|
|
||||||
TcpClient client,
|
|
||||||
bool secure,
|
|
||||||
string host,
|
|
||||||
System.Net.Security.RemoteCertificateValidationCallback validationCallback)
|
|
||||||
{
|
|
||||||
var netStream = client.GetStream ();
|
|
||||||
if (secure) {
|
|
||||||
if (validationCallback == null)
|
|
||||||
validationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
|
|
||||||
|
|
||||||
var sslStream = new SslStream (netStream, false, validationCallback);
|
|
||||||
sslStream.AuthenticateAsClient (host);
|
|
||||||
|
|
||||||
return new WsStream (sslStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WsStream (netStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static WsStream CreateServerStream (
|
|
||||||
TcpClient client, bool secure, X509Certificate cert)
|
|
||||||
{
|
|
||||||
var netStream = client.GetStream ();
|
|
||||||
if (secure) {
|
|
||||||
var sslStream = new SslStream (netStream, false);
|
|
||||||
sslStream.AuthenticateAsServer (cert);
|
|
||||||
|
|
||||||
return new WsStream (sslStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WsStream (netStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static WsStream CreateServerStream (HttpListenerContext context)
|
|
||||||
{
|
|
||||||
var conn = context.Connection;
|
|
||||||
return new WsStream (conn.Stream, conn.IsSecure);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal T ReadHandshake<T> (Func<string [], T> parser, int millisecondsTimeout)
|
internal T ReadHandshake<T> (Func<string [], T> parser, int millisecondsTimeout)
|
||||||
where T : HandshakeBase
|
where T : HandshakeBase
|
||||||
{
|
{
|
||||||
@ -245,6 +205,46 @@ namespace WebSocketSharp
|
|||||||
_innerStream.Close ();
|
_innerStream.Close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WsStream CreateClientStream (
|
||||||
|
TcpClient client,
|
||||||
|
bool secure,
|
||||||
|
string host,
|
||||||
|
System.Net.Security.RemoteCertificateValidationCallback validationCallback)
|
||||||
|
{
|
||||||
|
var netStream = client.GetStream ();
|
||||||
|
if (secure) {
|
||||||
|
if (validationCallback == null)
|
||||||
|
validationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
|
||||||
|
|
||||||
|
var sslStream = new SslStream (netStream, false, validationCallback);
|
||||||
|
sslStream.AuthenticateAsClient (host);
|
||||||
|
|
||||||
|
return new WsStream (sslStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WsStream (netStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WsStream CreateServerStream (
|
||||||
|
TcpClient client, bool secure, X509Certificate cert)
|
||||||
|
{
|
||||||
|
var netStream = client.GetStream ();
|
||||||
|
if (secure) {
|
||||||
|
var sslStream = new SslStream (netStream, false);
|
||||||
|
sslStream.AuthenticateAsServer (cert);
|
||||||
|
|
||||||
|
return new WsStream (sslStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WsStream (netStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WsStream CreateServerStream (HttpListenerContext context)
|
||||||
|
{
|
||||||
|
var conn = context.Connection;
|
||||||
|
return new WsStream (conn.Stream, conn.IsSecure);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose ()
|
public void Dispose ()
|
||||||
{
|
{
|
||||||
_innerStream.Dispose ();
|
_innerStream.Dispose ();
|
||||||
|
Loading…
Reference in New Issue
Block a user