Added the Ext.UTF8Encode method
This commit is contained in:
parent
f8f68e49b0
commit
cd886d32df
@ -848,6 +848,11 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static byte[] UTF8Encode (this string s)
|
||||||
|
{
|
||||||
|
return Encoding.UTF8.GetBytes (s);
|
||||||
|
}
|
||||||
|
|
||||||
internal static void WriteBytes (this Stream stream, byte[] bytes)
|
internal static void WriteBytes (this Stream stream, byte[] bytes)
|
||||||
{
|
{
|
||||||
using (var input = new MemoryStream (bytes))
|
using (var input = new MemoryStream (bytes))
|
||||||
|
@ -415,7 +415,7 @@ namespace WebSocketSharp.Server
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes (data);
|
var bytes = data.UTF8Encode ();
|
||||||
if (bytes.LongLength <= WebSocket.FragmentLength)
|
if (bytes.LongLength <= WebSocket.FragmentLength)
|
||||||
broadcast (Opcode.Text, bytes, null);
|
broadcast (Opcode.Text, bytes, null);
|
||||||
else
|
else
|
||||||
@ -476,7 +476,7 @@ namespace WebSocketSharp.Server
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes (data);
|
var bytes = data.UTF8Encode ();
|
||||||
if (bytes.LongLength <= WebSocket.FragmentLength)
|
if (bytes.LongLength <= WebSocket.FragmentLength)
|
||||||
broadcastAsync (Opcode.Text, bytes, completed);
|
broadcastAsync (Opcode.Text, bytes, completed);
|
||||||
else
|
else
|
||||||
|
@ -423,7 +423,7 @@ namespace WebSocketSharp.Server
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes (data);
|
var bytes = data.UTF8Encode ();
|
||||||
if (bytes.LongLength <= WebSocket.FragmentLength)
|
if (bytes.LongLength <= WebSocket.FragmentLength)
|
||||||
broadcast (Opcode.Text, bytes, null);
|
broadcast (Opcode.Text, bytes, null);
|
||||||
else
|
else
|
||||||
@ -484,7 +484,7 @@ namespace WebSocketSharp.Server
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes (data);
|
var bytes = data.UTF8Encode ();
|
||||||
if (bytes.LongLength <= WebSocket.FragmentLength)
|
if (bytes.LongLength <= WebSocket.FragmentLength)
|
||||||
broadcastAsync (Opcode.Text, bytes, completed);
|
broadcastAsync (Opcode.Text, bytes, completed);
|
||||||
else
|
else
|
||||||
|
@ -1601,7 +1601,7 @@ namespace WebSocketSharp
|
|||||||
? "MandatoryExtension cannot be used by the server."
|
? "MandatoryExtension cannot be used by the server."
|
||||||
: code == (ushort) CloseStatusCode.ServerError && client
|
: code == (ushort) CloseStatusCode.ServerError && client
|
||||||
? "ServerError cannot be used by the client."
|
? "ServerError cannot be used by the client."
|
||||||
: !reason.IsNullOrEmpty () && Encoding.UTF8.GetBytes (reason).Length > 123
|
: !reason.IsNullOrEmpty () && reason.UTF8Encode ().Length > 123
|
||||||
? "A reason has greater than the allowable max size."
|
? "A reason has greater than the allowable max size."
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
@ -1614,14 +1614,14 @@ namespace WebSocketSharp
|
|||||||
? "MandatoryExtension cannot be used by the server."
|
? "MandatoryExtension cannot be used by the server."
|
||||||
: code == CloseStatusCode.ServerError && client
|
: code == CloseStatusCode.ServerError && client
|
||||||
? "ServerError cannot be used by the client."
|
? "ServerError cannot be used by the client."
|
||||||
: !reason.IsNullOrEmpty () && Encoding.UTF8.GetBytes (reason).Length > 123
|
: !reason.IsNullOrEmpty () && reason.UTF8Encode ().Length > 123
|
||||||
? "A reason has greater than the allowable max size."
|
? "A reason has greater than the allowable max size."
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string CheckPingParameter (string message, out byte[] bytes)
|
internal static string CheckPingParameter (string message, out byte[] bytes)
|
||||||
{
|
{
|
||||||
bytes = Encoding.UTF8.GetBytes (message);
|
bytes = message.UTF8Encode ();
|
||||||
return bytes.Length > 125 ? "A message has greater than the allowable max size." : null;
|
return bytes.Length > 125 ? "A message has greater than the allowable max size." : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1710,7 +1710,7 @@ namespace WebSocketSharp
|
|||||||
var buff = new StringBuilder (base64Key, 64);
|
var buff = new StringBuilder (base64Key, 64);
|
||||||
buff.Append (_guid);
|
buff.Append (_guid);
|
||||||
SHA1 sha1 = new SHA1CryptoServiceProvider ();
|
SHA1 sha1 = new SHA1CryptoServiceProvider ();
|
||||||
var src = sha1.ComputeHash (Encoding.UTF8.GetBytes (buff.ToString ()));
|
var src = sha1.ComputeHash (buff.ToString ().UTF8Encode ());
|
||||||
|
|
||||||
return Convert.ToBase64String (src);
|
return Convert.ToBase64String (src);
|
||||||
}
|
}
|
||||||
@ -2326,7 +2326,7 @@ namespace WebSocketSharp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
send (Opcode.Text, new MemoryStream (Encoding.UTF8.GetBytes (data)));
|
send (Opcode.Text, new MemoryStream (data.UTF8Encode ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -2414,7 +2414,7 @@ namespace WebSocketSharp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendAsync (Opcode.Text, new MemoryStream (Encoding.UTF8.GetBytes (data)), completed);
|
sendAsync (Opcode.Text, new MemoryStream (data.UTF8Encode ()), completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user