[Modify] Replace it

This commit is contained in:
sta 2016-03-23 14:57:26 +09:00
parent f892fecb9a
commit ea97ab3fd6

View File

@ -2867,49 +2867,60 @@ namespace WebSocketSharp
public void SetProxy (string url, string username, string password)
{
lock (_forConn) {
var msg = checkIfAvailable (true, false, true, false, false, true);
if (msg == null) {
if (url.IsNullOrEmpty ()) {
_proxyUri = null;
_proxyCredentials = null;
_logger.Warn ("The proxy url and credentials were set back to the default.");
return;
}
Uri uri;
if (!Uri.TryCreate (url, UriKind.Absolute, out uri) ||
uri.Scheme != "http" ||
uri.Segments.Length > 1) {
msg = "The syntax of a proxy url must be 'http://<host>[:<port>]'.";
}
else {
_proxyUri = uri;
if (username.IsNullOrEmpty ()) {
_proxyCredentials = null;
_logger.Warn ("The proxy credentials were set back to the default.");
return;
}
msg = username.Contains (':') || !username.IsText ()
? "'username' contains an invalid character."
: !password.IsNullOrEmpty () && !password.IsText ()
? "'password' contains an invalid character."
: null;
}
}
if (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 proxy.", null);
return;
}
_proxyCredentials = new NetworkCredential (
username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port));
if (url.IsNullOrEmpty ()) {
_proxyUri = null;
_proxyCredentials = null;
_logger.Warn ("The proxy url and credentials were set back to the default.");
return;
}
Uri uri;
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 ()) {
_proxyUri = uri;
_proxyCredentials = null;
_logger.Warn ("The proxy credentials were set back to the default.");
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 =
new NetworkCredential (
username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port)
);
}
}