Skip to content

Commit ee7485f

Browse files
committed
[Modify] Add it
1 parent d355fa7 commit ee7485f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

websocket-sharp/WebSocket.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,40 @@ internal static string CheckCloseParameters (CloseStatusCode code, string reason
19481948
: null;
19491949
}
19501950

1951+
internal static bool CheckParametersForClose (
1952+
ushort code, string reason, bool client, out string message
1953+
)
1954+
{
1955+
message = null;
1956+
1957+
if (!code.IsCloseStatusCode ()) {
1958+
message = "'code' is an invalid close status code.";
1959+
return false;
1960+
}
1961+
1962+
if (code == (ushort) CloseStatusCode.NoStatus && !reason.IsNullOrEmpty ()) {
1963+
message = "'code' cannot have a reason.";
1964+
return false;
1965+
}
1966+
1967+
if (code == (ushort) CloseStatusCode.MandatoryExtension && !client) {
1968+
message = "'code' cannot be used by a server.";
1969+
return false;
1970+
}
1971+
1972+
if (code == (ushort) CloseStatusCode.ServerError && client) {
1973+
message = "'code' cannot be used by a client.";
1974+
return false;
1975+
}
1976+
1977+
if (!reason.IsNullOrEmpty () && reason.UTF8Encode ().Length > 123) {
1978+
message = "'reason' has greater than the allowable max size.";
1979+
return false;
1980+
}
1981+
1982+
return true;
1983+
}
1984+
19511985
internal static string CheckPingParameter (string message, out byte[] bytes)
19521986
{
19531987
bytes = message.UTF8Encode ();

0 commit comments

Comments
 (0)