|
|
|
|
@ -2867,8 +2867,14 @@ 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) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (url.IsNullOrEmpty ()) {
|
|
|
|
|
_proxyUri = null;
|
|
|
|
|
_proxyCredentials = null;
|
|
|
|
|
@ -2878,38 +2884,43 @@ namespace WebSocketSharp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>]'.";
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_proxyUri = uri;
|
|
|
|
|
|
|
|
|
|
if (username.IsNullOrEmpty ()) {
|
|
|
|
|
_proxyUri = uri;
|
|
|
|
|
_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 (username.Contains (':') || !username.IsText ()) {
|
|
|
|
|
_logger.Error ("'username' contains an invalid character.");
|
|
|
|
|
error ("An error has occurred in setting the proxy.", null);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
if (!password.IsNullOrEmpty () && !password.IsText ()) {
|
|
|
|
|
_logger.Error ("'password' contains an invalid character.");
|
|
|
|
|
error ("An error has occurred in setting the proxy.", null);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_proxyCredentials = new NetworkCredential (
|
|
|
|
|
username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port));
|
|
|
|
|
_proxyUri = uri;
|
|
|
|
|
_proxyCredentials =
|
|
|
|
|
new NetworkCredential (
|
|
|
|
|
username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|