diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 91983f89..42f50de6 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -508,6 +508,16 @@ namespace WebSocketSharp return value.StartsWith (method.ToExtensionString ()); } + internal static bool IsControl (this byte opcode) + { + return opcode > 0x7 && opcode < 0x10; + } + + internal static bool IsData (this byte opcode) + { + return opcode == 0x1 || opcode == 0x2; + } + internal static bool IsPortNumber (this int value) { return value > 0 && value < 65536; @@ -529,6 +539,11 @@ namespace WebSocketSharp code == CloseStatusCode.TlsHandshakeFailure; } + internal static bool IsSupported (this byte opcode) + { + return Enum.IsDefined (typeof (Opcode), opcode); + } + internal static bool IsText (this string value) { var len = value.Length; diff --git a/websocket-sharp/WebSocketFrame.cs b/websocket-sharp/WebSocketFrame.cs index bf247a10..c81720fd 100644 --- a/websocket-sharp/WebSocketFrame.cs +++ b/websocket-sharp/WebSocketFrame.cs @@ -377,33 +377,16 @@ namespace WebSocketSharp return output.ToString (); } - private static bool isControl (byte opcode) - { - return opcode == (byte) Opcode.Close || - opcode == (byte) Opcode.Ping || - opcode == (byte) Opcode.Pong; - } - private static bool isControl (Opcode opcode) { return opcode == Opcode.Close || opcode == Opcode.Ping || opcode == Opcode.Pong; } - private static bool isData (byte opcode) - { - return opcode == (byte) Opcode.Text || opcode == (byte) Opcode.Binary; - } - private static bool isData (Opcode opcode) { return opcode == Opcode.Text || opcode == Opcode.Binary; } - private static bool isSupported (byte opcode) - { - return Enum.IsDefined (typeof (Opcode), opcode); - } - private static string print (WebSocketFrame frame) { // Payload Length @@ -478,13 +461,13 @@ Extended Payload Length: {7} var payloadLen = (byte) (header[1] & 0x7f); // Check if valid header. - var err = !isSupported (opcode) + var err = !opcode.IsSupported () ? "An unsupported opcode." - : isControl (opcode) && fin == Fin.More + : opcode.IsControl () && fin == Fin.More ? "A control frame is fragmented." - : isControl (opcode) && payloadLen > 125 + : opcode.IsControl () && payloadLen > 125 ? "A control frame has a long payload length." - : !isData (opcode) && rsv1 == Rsv.On + : !opcode.IsData () && rsv1 == Rsv.On ? "A non data frame is compressed." : null;