[Modify] Use it

This commit is contained in:
sta 2016-08-17 15:24:40 +09:00
parent f6bd883264
commit ffa0b10fe6

View File

@ -2940,6 +2940,13 @@ namespace WebSocketSharp
return; return;
} }
if (!checkParametersForSetProxy (url, username, password, out msg)) {
_logger.Error (msg);
error ("An error has occurred in setting the proxy.", null);
return;
}
lock (_forState) { lock (_forState) {
if (!checkIfAvailable (true, false, false, true, out msg)) { if (!checkIfAvailable (true, false, false, true, out msg)) {
_logger.Error (msg); _logger.Error (msg);
@ -2949,47 +2956,22 @@ namespace WebSocketSharp
} }
if (url.IsNullOrEmpty ()) { if (url.IsNullOrEmpty ()) {
_logger.Warn ("The proxy url and credentials are set back to the default."); _logger.Warn ("The url and credentials for the proxy are initialized.");
_proxyUri = null; _proxyUri = null;
_proxyCredentials = null; _proxyCredentials = null;
return; return;
} }
Uri uri; _proxyUri = new Uri (url);
if (!Uri.TryCreate (url, UriKind.Absolute, out uri)
|| uri.Scheme != "http"
|| uri.Segments.Length > 1
) {
_logger.Error ("The syntax of a proxy url must be 'http://<host>[:<port>]'.");
error ("An error has occurred in setting the proxy.", null);
return;
}
if (username.IsNullOrEmpty ()) { if (username.IsNullOrEmpty ()) {
_logger.Warn ("The proxy credentials are set back to the default."); _logger.Warn ("The credentials for the proxy are initialized.");
_proxyUri = uri;
_proxyCredentials = null; _proxyCredentials = null;
return; return;
} }
if (username.Contains (':') || !username.IsText ()) {
_logger.Error ("'username' contains an invalid character.");
error ("An error has occurred in setting the proxy.", null);
return;
}
if (!password.IsNullOrEmpty () && !password.IsText ()) {
_logger.Error ("'password' contains an invalid character.");
error ("An error has occurred in setting the proxy.", null);
return;
}
_proxyUri = uri;
_proxyCredentials = _proxyCredentials =
new NetworkCredential ( new NetworkCredential (
username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port) username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port)