[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 ()) {
Uri uri;
if (!Uri.TryCreate (value, UriKind.Absolute, out uri)) {
msg = "Not an absolute URI string.";
throw new ArgumentException (msg, value);
} }
if (value.IsNullOrEmpty ()) { if (uri.Segments.Length > 1) {
_origin = value; msg = "It includes the path segments.";
return; throw new ArgumentException (msg, value);
} }
}
Uri origin; if (!canSet (out msg)) {
if (!Uri.TryCreate (value, UriKind.Absolute, out origin) || origin.Segments.Length > 1) { _logger.Warn (msg);
_logger.Error ("The syntax of an origin must be '<scheme>://<host>[:<port>]'."); return;
error ("An error has occurred in setting the origin.", null); }
lock (_forState) {
if (!canSet (out msg)) {
_logger.Warn (msg);
return; return;
} }
_origin = value.TrimEnd ('/'); _origin = !value.IsNullOrEmpty () ? value.TrimEnd ('/') : value;
} }
} }
} }

Loading…
Cancel
Save