Added the Ext.UTF8Encode method

This commit is contained in:
sta 2015-08-23 16:31:18 +09:00
parent f8f68e49b0
commit cd886d32df
4 changed files with 15 additions and 10 deletions

View File

@ -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)
{
using (var input = new MemoryStream (bytes))

View File

@ -415,7 +415,7 @@ namespace WebSocketSharp.Server
return;
}
var bytes = Encoding.UTF8.GetBytes (data);
var bytes = data.UTF8Encode ();
if (bytes.LongLength <= WebSocket.FragmentLength)
broadcast (Opcode.Text, bytes, null);
else
@ -476,7 +476,7 @@ namespace WebSocketSharp.Server
return;
}
var bytes = Encoding.UTF8.GetBytes (data);
var bytes = data.UTF8Encode ();
if (bytes.LongLength <= WebSocket.FragmentLength)
broadcastAsync (Opcode.Text, bytes, completed);
else

View File

@ -423,7 +423,7 @@ namespace WebSocketSharp.Server
return;
}
var bytes = Encoding.UTF8.GetBytes (data);
var bytes = data.UTF8Encode ();
if (bytes.LongLength <= WebSocket.FragmentLength)
broadcast (Opcode.Text, bytes, null);
else
@ -484,7 +484,7 @@ namespace WebSocketSharp.Server
return;
}
var bytes = Encoding.UTF8.GetBytes (data);
var bytes = data.UTF8Encode ();
if (bytes.LongLength <= WebSocket.FragmentLength)
broadcastAsync (Opcode.Text, bytes, completed);
else

View File

@ -1601,7 +1601,7 @@ namespace WebSocketSharp
? "MandatoryExtension cannot be used by the server."
: code == (ushort) CloseStatusCode.ServerError && 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."
: null;
}
@ -1614,14 +1614,14 @@ namespace WebSocketSharp
? "MandatoryExtension cannot be used by the server."
: code == CloseStatusCode.ServerError && 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."
: null;
}
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;
}
@ -1710,7 +1710,7 @@ namespace WebSocketSharp
var buff = new StringBuilder (base64Key, 64);
buff.Append (_guid);
SHA1 sha1 = new SHA1CryptoServiceProvider ();
var src = sha1.ComputeHash (Encoding.UTF8.GetBytes (buff.ToString ()));
var src = sha1.ComputeHash (buff.ToString ().UTF8Encode ());
return Convert.ToBase64String (src);
}
@ -2326,7 +2326,7 @@ namespace WebSocketSharp
return;
}
send (Opcode.Text, new MemoryStream (Encoding.UTF8.GetBytes (data)));
send (Opcode.Text, new MemoryStream (data.UTF8Encode ()));
}
/// <summary>
@ -2414,7 +2414,7 @@ namespace WebSocketSharp
return;
}
sendAsync (Opcode.Text, new MemoryStream (Encoding.UTF8.GetBytes (data)), completed);
sendAsync (Opcode.Text, new MemoryStream (data.UTF8Encode ()), completed);
}
/// <summary>