15 private bool _UseRegistry;
17 private bool _BypassOnLocal;
19 private bool m_EnableAutoproxy;
21 private Uri _ProxyAddress;
27 private Regex[] _RegExBypassList;
31 private AutoWebProxyScriptEngine m_ScriptEngine;
46 _ProxyHostAddresses =
null;
47 _ProxyAddress = value;
51 internal bool AutoDetect
55 if (ScriptEngine ==
null)
57 ScriptEngine =
new AutoWebProxyScriptEngine(
this, useRegistry:
false);
59 ScriptEngine.AutomaticallyDetectSettings = value;
63 internal Uri ScriptLocation
67 if (ScriptEngine ==
null)
69 ScriptEngine =
new AutoWebProxyScriptEngine(
this, useRegistry:
false);
71 ScriptEngine.AutomaticConfigurationScript = value;
83 return _BypassOnLocal;
89 _BypassOnLocal = value;
100 if (_BypassList ==
null)
104 return (
string[])_BypassList.
ToArray(typeof(
string));
108 _UseRegistry =
false;
109 DeleteScriptEngine();
111 UpdateRegExList(canThrow:
true);
126 _Credentials = value;
157 if (_BypassList ==
null)
165 internal AutoWebProxyScriptEngine ScriptEngine
169 return m_ScriptEngine;
173 m_ScriptEngine = value;
179 : this((
Uri)null, BypassOnLocal: false, (string[])null, (
ICredentials)null)
186 : this(
Address, BypassOnLocal: false, null, null)
195 : this(
Address, BypassOnLocal, null, null)
218 _BypassOnLocal = BypassOnLocal;
222 UpdateRegExList(canThrow:
true);
225 m_EnableAutoproxy =
true;
242 : this(CreateProxyUri(
Address), BypassOnLocal: false, null, null)
253 : this(CreateProxyUri(
Address), BypassOnLocal, null, null)
282 internal void CheckForChanges()
284 if (ScriptEngine !=
null)
286 ScriptEngine.CheckForChanges();
296 if (destination ==
null)
300 if (GetProxyAuto(destination, out
Uri proxyUri))
304 if (IsBypassedManual(destination))
308 Hashtable proxyHostAddresses = _ProxyHostAddresses;
309 Uri uri = (proxyHostAddresses !=
null) ? (proxyHostAddresses[destination.
Scheme] as
Uri) : _ProxyAddress;
317 private static Uri CreateProxyUri(
string address)
323 if (address.IndexOf(
"://") == -1)
325 address =
"http://" + address;
327 return new Uri(address);
330 private void UpdateRegExList(
bool canThrow)
332 Regex[] array =
null;
336 if (bypassList !=
null && bypassList.
Count > 0)
339 for (
int i = 0; i < bypassList.
Count; i++)
349 _RegExBypassList =
null;
354 _RegExBypassList = array;
357 private bool IsMatchInBypassList(Uri input)
359 UpdateRegExList(canThrow:
false);
360 if (_RegExBypassList ==
null)
364 string input2 = input.Scheme +
"://" + input.Host + ((!input.IsDefaultPort) ? (
":" + input.Port) :
"");
365 for (
int i = 0; i < _BypassList.
Count; i++)
367 if (_RegExBypassList[i].IsMatch(input2))
375 private bool IsLocal(Uri host)
377 string host2 = host.Host;
378 if (IPAddress.TryParse(host2, out IPAddress address))
380 if (!IPAddress.IsLoopback(address))
382 return NclUtilities.IsAddressLocal(address);
386 int num = host2.IndexOf(
'.');
392 if (text !=
null && text.Length == host2.Length - num &&
string.Compare(text, 0, host2, num, text.Length,
StringComparison.OrdinalIgnoreCase) == 0)
399 private bool IsLocalInProxyHash(Uri host)
401 Hashtable proxyHostAddresses = _ProxyHostAddresses;
402 if (proxyHostAddresses !=
null)
404 Uri uri = (Uri)proxyHostAddresses[host.Scheme];
424 if (IsBypassedAuto(host, out
bool isBypassed))
428 return IsBypassedManual(host);
431 private bool IsBypassedManual(
Uri host)
437 if ((!(_ProxyAddress ==
null) || _ProxyHostAddresses !=
null) && (!_BypassOnLocal || !IsLocal(host)) && !IsMatchInBypassList(host))
439 return IsLocalInProxyHash(host);
446 [Obsolete(
"This method has been deprecated. Please use the proxy selected for you by default. http://go.microsoft.com/fwlink/?linkid=14202")]
449 ExceptionHelper.WebPermissionUnrestricted.Demand();
450 return new WebProxy(enableAutoproxy:
true);
461 flag = serializationInfo.
GetBoolean(
"_UseRegistry");
468 ExceptionHelper.WebPermissionUnrestricted.Demand();
469 UnsafeUpdateFromRegistry();
472 _ProxyAddress = (
Uri)serializationInfo.
GetValue(
"_ProxyAddress", typeof(
Uri));
473 _BypassOnLocal = serializationInfo.
GetBoolean(
"_BypassOnLocal");
490 GetObjectData(serializationInfo, streamingContext);
499 serializationInfo.
AddValue(
"_BypassOnLocal", _BypassOnLocal);
500 serializationInfo.
AddValue(
"_ProxyAddress", _ProxyAddress);
501 serializationInfo.
AddValue(
"_BypassList", _BypassList);
505 serializationInfo.
AddValue(
"_UseRegistry", value:
true);
509 internal WebProxy(
bool enableAutoproxy)
511 m_EnableAutoproxy = enableAutoproxy;
512 UnsafeUpdateFromRegistry();
515 internal void DeleteScriptEngine()
517 if (ScriptEngine !=
null)
519 ScriptEngine.Close();
524 internal void UnsafeUpdateFromRegistry()
527 ScriptEngine =
new AutoWebProxyScriptEngine(
this, useRegistry:
true);
528 WebProxyData webProxyData = ScriptEngine.GetWebProxyData();
529 Update(webProxyData);
532 internal void Update(WebProxyData webProxyData)
536 _BypassOnLocal = webProxyData.bypassOnLocal;
537 _ProxyAddress = webProxyData.proxyAddress;
538 _ProxyHostAddresses = webProxyData.proxyHostAddresses;
539 _BypassList = webProxyData.bypassList;
540 ScriptEngine.AutomaticallyDetectSettings = (m_EnableAutoproxy && webProxyData.automaticallyDetectSettings);
541 ScriptEngine.AutomaticConfigurationScript = (m_EnableAutoproxy ? webProxyData.scriptLocation :
null);
545 ProxyChain IAutoWebProxy.GetProxies(Uri destination)
547 if (destination ==
null)
549 throw new ArgumentNullException(
"destination");
551 return new ProxyScriptChain(
this, destination);
554 private bool GetProxyAuto(Uri destination, out Uri proxyUri)
557 if (ScriptEngine ==
null)
562 if (!ScriptEngine.GetProxies(destination, out proxyList))
566 if (proxyList.Count > 0)
568 if (AreAllBypassed(proxyList, checkFirstOnly:
true))
570 proxyUri = destination;
574 proxyUri = ProxyUri(proxyList[0]);
580 private bool IsBypassedAuto(Uri destination, out
bool isBypassed)
583 if (ScriptEngine ==
null)
587 if (!ScriptEngine.GetProxies(destination, out
IList<string> proxyList))
591 if (proxyList.Count == 0)
597 isBypassed = AreAllBypassed(proxyList, checkFirstOnly:
true);
602 internal Uri[] GetProxiesAuto(Uri destination, ref
int syncStatus)
604 if (ScriptEngine ==
null)
609 if (!ScriptEngine.GetProxies(destination, out proxyList, ref syncStatus))
614 if (proxyList.Count == 0)
618 else if (AreAllBypassed(proxyList, checkFirstOnly:
false))
624 array =
new Uri[proxyList.Count];
625 for (
int i = 0; i < proxyList.Count; i++)
627 array[i] = ProxyUri(proxyList[i]);
633 internal void AbortGetProxiesAuto(ref
int syncStatus)
635 if (ScriptEngine !=
null)
637 ScriptEngine.Abort(ref syncStatus);
641 internal Uri GetProxyAutoFailover(Uri destination)
643 if (IsBypassedManual(destination))
647 Uri result = _ProxyAddress;
648 Hashtable proxyHostAddresses = _ProxyHostAddresses;
649 if (proxyHostAddresses !=
null)
651 result = (proxyHostAddresses[destination.Scheme] as Uri);
659 foreach (
string proxy
in proxies)
661 flag =
string.IsNullOrEmpty(proxy);
674 private static Uri ProxyUri(
string proxyName)
676 if (proxyName !=
null && proxyName.Length != 0)
678 return new Uri(
"http://" + proxyName);
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
bool? UseDefaultCredentials
Gets or sets a T:System.Boolean value that controls whether the P:System.Net.CredentialCache....
bool GetBoolean(string name)
Retrieves a Boolean value from the T:System.Runtime.Serialization.SerializationInfo store.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
The Host header, which specifies the host name and port number of the resource being requested.
string Scheme
Gets the scheme name for this URI.
WebProxy(SerializationInfo serializationInfo, StreamingContext streamingContext)
Initializes an instance of the T:System.Net.WebProxy class using previously serialized content.
WebProxy(string Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials)
Initializes a new instance of the T:System.Net.WebProxy class with the specified URI,...
Compare strings using culture-sensitive sort rules and the invariant culture.
bool IsLoopback
Gets whether the specified T:System.Uri references the local host.
WebProxy(string Address, bool BypassOnLocal)
Initializes a new instance of the T:System.Net.WebProxy class with the specified URI and bypass setti...
Describes the source and destination of a given serialized stream, and provides an additional caller-...
WebProxy()
Initializes an empty instance of the T:System.Net.WebProxy class.
SecurityAction
Specifies the security actions that can be performed using declarative security.
void AddValue(string name, object value, Type type)
Adds a value into the T:System.Runtime.Serialization.SerializationInfo store, where value is associa...
WebProxy(Uri Address)
Initializes a new instance of the T:System.Net.WebProxy class from the specified T:System....
WebProxy(string Host, int Port)
Initializes a new instance of the T:System.Net.WebProxy class with the specified host and port number...
WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList)
Initializes a new instance of the T:System.Net.WebProxy class with the specified T:System....
Uri Address
Gets or sets the address of the proxy server.
Provides storage for multiple credentials.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
static ICredentials DefaultCredentials
Gets the system credentials of the application.
Uri GetProxy(Uri destination)
Returns the proxied URI for a request.
virtual void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data that is needed to serializ...
Provides the base authentication interface for retrieving credentials for Web client authentication.
ArrayList BypassArrayList
Gets a list of addresses that do not use the proxy server.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
ICredentials Credentials
Gets or sets the credentials to submit to the proxy server for authentication.
RegexOptions
Provides enumerated values to use to set regular expression options.
Allows an object to control its own serialization and deserialization.
string [] BypassList
Gets or sets an array of addresses that do not use the proxy server.
The P:System.Uri.Port data.
bool BypassProxyOnLocal
Gets or sets a value that indicates whether to bypass the proxy server for local addresses.
static WebProxy GetDefaultProxy()
Reads the Internet Explorer nondynamic proxy settings.
bool IsBypassed(Uri host)
Indicates whether to use the proxy server for the specified host.
object GetValue(string name, Type type)
Retrieves a value from the T:System.Runtime.Serialization.SerializationInfo store.
Specifies that the class can be serialized.
WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials)
Initializes a new instance of the T:System.Net.WebProxy class with the specified T:System....
Provides the base interface for implementation of proxy access for the T:System.Net....
Provides information about a specific culture (called a locale for unmanaged code development)....
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
WebProxy(string Address, bool BypassOnLocal, string[] BypassList)
Initializes a new instance of the T:System.Net.WebProxy class with the specified URI,...
WebProxy(string Address)
Initializes a new instance of the T:System.Net.WebProxy class with the specified URI.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
Represents an immutable regular expression.To browse the .NET Framework source code for this type,...
WebProxy(Uri Address, bool BypassOnLocal)
Initializes a new instance of the T:System.Net.WebProxy class with the T:System.Uri instance and bypa...
Contains HTTP proxy settings for the T:System.Net.WebRequest class.
virtual object [] ToArray()
Copies the elements of the T:System.Collections.ArrayList to a new T:System.Object array.
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...