[Modify] Replace it

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

View File

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