From 4ce77fb5c56441a417141564761d875953660894 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 1 Jun 2017 16:25:07 +0900 Subject: [PATCH] [Modify] It throws exceptions --- websocket-sharp/Server/HttpServer.cs | 48 +++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index a7f84f69..f15cdc8c 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -1127,12 +1127,52 @@ namespace WebSocketSharp.Server /// A that represents the reason for the WebSocket /// connection close. The size must be 123 bytes or less. /// + /// + /// The size of is greater than 123 bytes. + /// + /// + /// + /// is + /// . + /// + /// + /// -or- + /// + /// + /// is + /// and + /// there is . + /// + /// + /// -or- + /// + /// + /// could not be UTF-8-encoded. + /// + /// public void Stop (CloseStatusCode code, string reason) { - string msg; - if (!WebSocket.CheckParametersForClose (code, reason, false, out msg)) { - _log.Error (msg); - return; + if (code == CloseStatusCode.MandatoryExtension) { + var msg = "MandatoryExtension cannot be used."; + throw new ArgumentException (msg, "code"); + } + + if (!reason.IsNullOrEmpty ()) { + if (code == CloseStatusCode.NoStatus) { + var msg = "NoStatus cannot be used."; + throw new ArgumentException (msg, "code"); + } + + byte[] bytes; + if (!reason.TryGetUTF8EncodedBytes (out bytes)) { + var msg = "It could not be UTF-8-encoded."; + throw new ArgumentException (msg, "reason"); + } + + if (bytes.Length > 123) { + var msg = "Its size is greater than 123 bytes."; + throw new ArgumentOutOfRangeException ("reason", msg); + } } stop ((ushort) code, reason);