[Modify] Throw exceptions

master
sta 8 years ago
parent 6a4d1c878b
commit fd2398316b

@ -547,29 +547,38 @@ namespace WebSocketSharp
} }
set { set {
lock (_forState) { string msg = null;
string msg;
if (!checkIfAvailable (true, false, true, false, false, true, out msg)) {
_logger.Error (msg);
error ("An error has occurred in setting the origin.", null);
return; if (!_client) {
msg = "This instance is not a client.";
throw new InvalidOperationException (msg);
} }
if (value.IsNullOrEmpty ()) { if (!value.IsNullOrEmpty ()) {
_origin = value; Uri uri;
return; if (!Uri.TryCreate (value, UriKind.Absolute, out uri)) {
msg = "Not an absolute URI string.";
throw new ArgumentException (msg, value);
} }
Uri origin; if (uri.Segments.Length > 1) {
if (!Uri.TryCreate (value, UriKind.Absolute, out origin) || origin.Segments.Length > 1) { msg = "It includes the path segments.";
_logger.Error ("The syntax of an origin must be '<scheme>://<host>[:<port>]'."); throw new ArgumentException (msg, value);
error ("An error has occurred in setting the origin.", null); }
}
if (!canSet (out msg)) {
_logger.Warn (msg);
return;
}
lock (_forState) {
if (!canSet (out msg)) {
_logger.Warn (msg);
return; return;
} }
_origin = value.TrimEnd ('/'); _origin = !value.IsNullOrEmpty () ? value.TrimEnd ('/') : value;
} }
} }
} }

Loading…
Cancel
Save