Files
Dec2017-Script-Dump/System/Net/WebProxy.cs
T
2026-06-04 11:42:34 +02:00

427 lines
19 KiB
C#

using System;
using System.Collections;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
namespace System.Net
{
/// <summary>Contains HTTP proxy settings for the <see cref="T:System.Net.WebRequest" /> class.</summary>
// Token: 0x0200026D RID: 621
[Serializable]
public class WebProxy : ISerializable, IWebProxy
{
/// <summary>Initializes an empty instance of the <see cref="T:System.Net.WebProxy" /> class.</summary>
// Token: 0x060016EC RID: 5868 RVA: 0x0004D4D0 File Offset: 0x0004B6D0
public WebProxy()
: this(null, false, null, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the specified URI.</summary>
/// <param name="Address">The URI of the proxy server. </param>
/// <exception cref="T:System.UriFormatException">
/// <paramref name="Address" /> is an invalid URI. </exception>
// Token: 0x060016ED RID: 5869 RVA: 0x0004D4DC File Offset: 0x0004B6DC
public WebProxy(string address)
: this(WebProxy.ToUri(address), false, null, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class from the specified <see cref="T:System.Uri" /> instance.</summary>
/// <param name="Address">A <see cref="T:System.Uri" /> instance that contains the address of the proxy server. </param>
// Token: 0x060016EE RID: 5870 RVA: 0x0004D4F0 File Offset: 0x0004B6F0
public WebProxy(global::System.Uri address)
: this(address, false, null, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the specified URI and bypass setting.</summary>
/// <param name="Address">The URI of the proxy server. </param>
/// <param name="BypassOnLocal">true to bypass the proxy for local addresses; otherwise, false. </param>
/// <exception cref="T:System.UriFormatException">
/// <paramref name="Address" /> is an invalid URI. </exception>
// Token: 0x060016EF RID: 5871 RVA: 0x0004D4FC File Offset: 0x0004B6FC
public WebProxy(string address, bool bypassOnLocal)
: this(WebProxy.ToUri(address), bypassOnLocal, null, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the specified host and port number.</summary>
/// <param name="Host">The name of the proxy host. </param>
/// <param name="Port">The port number on <paramref name="Host" /> to use. </param>
/// <exception cref="T:System.UriFormatException">The URI formed by combining <paramref name="Host" /> and <paramref name="Port" /> is not a valid URI. </exception>
// Token: 0x060016F0 RID: 5872 RVA: 0x0004D510 File Offset: 0x0004B710
public WebProxy(string host, int port)
: this(new global::System.Uri(string.Concat(new object[] { "http://", host, ":", port })))
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the <see cref="T:System.Uri" /> instance and bypass setting.</summary>
/// <param name="Address">A <see cref="T:System.Uri" /> instance that contains the address of the proxy server. </param>
/// <param name="BypassOnLocal">true to bypass the proxy for local addresses; otherwise, false. </param>
// Token: 0x060016F1 RID: 5873 RVA: 0x0004D548 File Offset: 0x0004B748
public WebProxy(global::System.Uri address, bool bypassOnLocal)
: this(address, bypassOnLocal, null, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the specified URI, bypass setting, and list of URIs to bypass.</summary>
/// <param name="Address">The URI of the proxy server. </param>
/// <param name="BypassOnLocal">true to bypass the proxy for local addresses; otherwise, false. </param>
/// <param name="BypassList">An array of regular expression strings that contain the URIs of the servers to bypass. </param>
/// <exception cref="T:System.UriFormatException">
/// <paramref name="Address" /> is an invalid URI. </exception>
// Token: 0x060016F2 RID: 5874 RVA: 0x0004D554 File Offset: 0x0004B754
public WebProxy(string address, bool bypassOnLocal, string[] bypassList)
: this(WebProxy.ToUri(address), bypassOnLocal, bypassList, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the specified <see cref="T:System.Uri" /> instance, bypass setting, and list of URIs to bypass.</summary>
/// <param name="Address">A <see cref="T:System.Uri" /> instance that contains the address of the proxy server. </param>
/// <param name="BypassOnLocal">true to bypass the proxy for local addresses; otherwise, false. </param>
/// <param name="BypassList">An array of regular expression strings that contains the URIs of the servers to bypass. </param>
// Token: 0x060016F3 RID: 5875 RVA: 0x0004D568 File Offset: 0x0004B768
public WebProxy(global::System.Uri address, bool bypassOnLocal, string[] bypassList)
: this(address, bypassOnLocal, bypassList, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the specified URI, bypass setting, list of URIs to bypass, and credentials.</summary>
/// <param name="Address">The URI of the proxy server. </param>
/// <param name="BypassOnLocal">true to bypass the proxy for local addresses; otherwise, false. </param>
/// <param name="BypassList">An array of regular expression strings that contains the URIs of the servers to bypass. </param>
/// <param name="Credentials">An <see cref="T:System.Net.ICredentials" /> instance to submit to the proxy server for authentication. </param>
/// <exception cref="T:System.UriFormatException">
/// <paramref name="Address" /> is an invalid URI. </exception>
// Token: 0x060016F4 RID: 5876 RVA: 0x0004D574 File Offset: 0x0004B774
public WebProxy(string address, bool bypassOnLocal, string[] bypassList, ICredentials credentials)
: this(WebProxy.ToUri(address), bypassOnLocal, bypassList, credentials)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.WebProxy" /> class with the specified <see cref="T:System.Uri" /> instance, bypass setting, list of URIs to bypass, and credentials.</summary>
/// <param name="Address">A <see cref="T:System.Uri" /> instance that contains the address of the proxy server. </param>
/// <param name="BypassOnLocal">true to bypass the proxy for local addresses; otherwise, false. </param>
/// <param name="BypassList">An array of regular expression strings that contains the URIs of the servers to bypass. </param>
/// <param name="Credentials">An <see cref="T:System.Net.ICredentials" /> instance to submit to the proxy server for authentication. </param>
// Token: 0x060016F5 RID: 5877 RVA: 0x0004D588 File Offset: 0x0004B788
public WebProxy(global::System.Uri address, bool bypassOnLocal, string[] bypassList, ICredentials credentials)
{
this.address = address;
this.bypassOnLocal = bypassOnLocal;
if (bypassList != null)
{
this.bypassList = new ArrayList(bypassList);
}
this.credentials = credentials;
this.CheckBypassList();
}
/// <summary>Initializes an instance of the <see cref="T:System.Net.WebProxy" /> class using previously serialized content.</summary>
/// <param name="serializationInfo">The serialization data. </param>
/// <param name="streamingContext">The context for the serialized data. </param>
// Token: 0x060016F6 RID: 5878 RVA: 0x0004D5CC File Offset: 0x0004B7CC
protected WebProxy(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
this.address = (global::System.Uri)serializationInfo.GetValue("_ProxyAddress", typeof(global::System.Uri));
this.bypassOnLocal = serializationInfo.GetBoolean("_BypassOnLocal");
this.bypassList = (ArrayList)serializationInfo.GetValue("_BypassList", typeof(ArrayList));
this.useDefaultCredentials = serializationInfo.GetBoolean("_UseDefaultCredentials");
this.credentials = null;
this.CheckBypassList();
}
/// <summary>Creates the serialization data and context that are used by the system to serialize a <see cref="T:System.Net.WebProxy" /> object.</summary>
/// <param name="serializationInfo">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object to populate with data. </param>
/// <param name="streamingContext">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> structure that indicates the destination for this serialization. </param>
// Token: 0x060016F7 RID: 5879 RVA: 0x0004D650 File Offset: 0x0004B850
void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
this.GetObjectData(serializationInfo, streamingContext);
}
/// <summary>Gets or sets the address of the proxy server.</summary>
/// <returns>A <see cref="T:System.Uri" /> instance that contains the address of the proxy server.</returns>
// Token: 0x1700074E RID: 1870
// (get) Token: 0x060016F8 RID: 5880 RVA: 0x0004D65C File Offset: 0x0004B85C
// (set) Token: 0x060016F9 RID: 5881 RVA: 0x0004D664 File Offset: 0x0004B864
public global::System.Uri Address
{
get
{
return this.address;
}
set
{
this.address = value;
}
}
/// <summary>Gets a list of addresses that do not use the proxy server.</summary>
/// <returns>An <see cref="T:System.Collections.ArrayList" /> that contains a list of <see cref="P:System.Net.WebProxy.BypassList" /> arrays that represents URIs that do not use the proxy server when accessed.</returns>
// Token: 0x1700074F RID: 1871
// (get) Token: 0x060016FA RID: 5882 RVA: 0x0004D670 File Offset: 0x0004B870
public ArrayList BypassArrayList
{
get
{
if (this.bypassList == null)
{
this.bypassList = new ArrayList();
}
return this.bypassList;
}
}
/// <summary>Gets or sets an array of addresses that do not use the proxy server.</summary>
/// <returns>An array that contains a list of regular expressions that describe URIs that do not use the proxy server when accessed.</returns>
// Token: 0x17000750 RID: 1872
// (get) Token: 0x060016FB RID: 5883 RVA: 0x0004D690 File Offset: 0x0004B890
// (set) Token: 0x060016FC RID: 5884 RVA: 0x0004D6AC File Offset: 0x0004B8AC
public string[] BypassList
{
get
{
return (string[])this.BypassArrayList.ToArray(typeof(string));
}
set
{
if (value == null)
{
throw new ArgumentNullException();
}
this.bypassList = new ArrayList(value);
this.CheckBypassList();
}
}
/// <summary>Gets or sets a value that indicates whether to bypass the proxy server for local addresses.</summary>
/// <returns>true to bypass the proxy server for local addresses; otherwise, false. The default value is false.</returns>
// Token: 0x17000751 RID: 1873
// (get) Token: 0x060016FD RID: 5885 RVA: 0x0004D6CC File Offset: 0x0004B8CC
// (set) Token: 0x060016FE RID: 5886 RVA: 0x0004D6D4 File Offset: 0x0004B8D4
public bool BypassProxyOnLocal
{
get
{
return this.bypassOnLocal;
}
set
{
this.bypassOnLocal = value;
}
}
/// <summary>Gets or sets the credentials to submit to the proxy server for authentication.</summary>
/// <returns>An <see cref="T:System.Net.ICredentials" /> instance that contains the credentials to submit to the proxy server for authentication.</returns>
/// <exception cref="T:System.InvalidOperationException">You attempted to set this property when the <see cref="P:System.Net.WebProxy.UseDefaultCredentials" /> property was set to true. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// </PermissionSet>
// Token: 0x17000752 RID: 1874
// (get) Token: 0x060016FF RID: 5887 RVA: 0x0004D6E0 File Offset: 0x0004B8E0
// (set) Token: 0x06001700 RID: 5888 RVA: 0x0004D6E8 File Offset: 0x0004B8E8
public ICredentials Credentials
{
get
{
return this.credentials;
}
set
{
this.credentials = value;
}
}
/// <summary>Gets or sets a <see cref="T:System.Boolean" /> value that controls whether the <see cref="P:System.Net.CredentialCache.DefaultCredentials" /> are sent with requests.</summary>
/// <returns>true if the default credentials are used; otherwise, false. The default value is false.</returns>
/// <exception cref="T:System.InvalidOperationException">You attempted to set this property when the <see cref="P:System.Net.WebProxy.Credentials" /> property contains credentials other than the default credentials. For more information, see the Remarks section.</exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="USERNAME" />
/// </PermissionSet>
// Token: 0x17000753 RID: 1875
// (get) Token: 0x06001701 RID: 5889 RVA: 0x0004D6F4 File Offset: 0x0004B8F4
// (set) Token: 0x06001702 RID: 5890 RVA: 0x0004D6FC File Offset: 0x0004B8FC
[global::System.MonoTODO("Does not affect Credentials, since CredentialCache.DefaultCredentials is not implemented.")]
public bool UseDefaultCredentials
{
get
{
return this.useDefaultCredentials;
}
set
{
this.useDefaultCredentials = value;
}
}
/// <summary>Reads the Internet Explorer nondynamic proxy settings.</summary>
/// <returns>A <see cref="T:System.Net.WebProxy" /> instance that contains the nondynamic proxy settings from Internet Explorer 5.5 and later.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// <IPermission class="System.Net.WebPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06001703 RID: 5891 RVA: 0x0004D708 File Offset: 0x0004B908
[Obsolete("This method has been deprecated", false)]
[global::System.MonoTODO("Can we get this info under windows from the system?")]
public static WebProxy GetDefaultProxy()
{
IWebProxy select = GlobalProxySelection.Select;
if (select is WebProxy)
{
return (WebProxy)select;
}
return new WebProxy();
}
/// <summary>Returns the proxied URI for a request.</summary>
/// <returns>The <see cref="T:System.Uri" /> instance of the Internet resource, if the resource is on the bypass list; otherwise, the <see cref="T:System.Uri" /> instance of the proxy.</returns>
/// <param name="destination">The <see cref="T:System.Uri" /> instance of the requested Internet resource. </param>
// Token: 0x06001704 RID: 5892 RVA: 0x0004D734 File Offset: 0x0004B934
public global::System.Uri GetProxy(global::System.Uri destination)
{
if (this.IsBypassed(destination))
{
return destination;
}
return this.address;
}
/// <summary>Indicates whether to use the proxy server for the specified host.</summary>
/// <returns>true if the proxy server should not be used for <paramref name="host" />; otherwise, false.</returns>
/// <param name="host">The <see cref="T:System.Uri" /> instance of the host to check for proxy use. </param>
// Token: 0x06001705 RID: 5893 RVA: 0x0004D74C File Offset: 0x0004B94C
public bool IsBypassed(global::System.Uri host)
{
if (host == null)
{
throw new ArgumentNullException("host");
}
if (host.IsLoopback && this.bypassOnLocal)
{
return true;
}
if (this.address == null)
{
return true;
}
string host2 = host.Host;
if (this.bypassOnLocal && host2.IndexOf('.') == -1)
{
return true;
}
if (!this.bypassOnLocal)
{
if (string.Compare(host2, "localhost", true, CultureInfo.InvariantCulture) == 0)
{
return true;
}
if (string.Compare(host2, "loopback", true, CultureInfo.InvariantCulture) == 0)
{
return true;
}
IPAddress ipaddress = null;
if (IPAddress.TryParse(host2, out ipaddress) && IPAddress.IsLoopback(ipaddress))
{
return true;
}
}
if (this.bypassList == null || this.bypassList.Count == 0)
{
return false;
}
bool flag;
try
{
string text = host.Scheme + "://" + host.Authority;
int i;
for (i = 0; i < this.bypassList.Count; i++)
{
global::System.Text.RegularExpressions.Regex regex = new global::System.Text.RegularExpressions.Regex((string)this.bypassList[i], global::System.Text.RegularExpressions.RegexOptions.IgnoreCase | global::System.Text.RegularExpressions.RegexOptions.Singleline);
if (regex.IsMatch(text))
{
break;
}
}
if (i == this.bypassList.Count)
{
flag = false;
}
else
{
while (i < this.bypassList.Count)
{
new global::System.Text.RegularExpressions.Regex((string)this.bypassList[i]);
i++;
}
flag = true;
}
}
catch (ArgumentException)
{
flag = false;
}
return flag;
}
/// <summary>Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with the data that is needed to serialize the target object.</summary>
/// <param name="serializationInfo">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to populate with data. </param>
/// <param name="streamingContext">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> that specifies the destination for this serialization.</param>
// Token: 0x06001706 RID: 5894 RVA: 0x0004D914 File Offset: 0x0004BB14
protected virtual void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
serializationInfo.AddValue("_BypassOnLocal", this.bypassOnLocal);
serializationInfo.AddValue("_ProxyAddress", this.address);
serializationInfo.AddValue("_BypassList", this.bypassList);
serializationInfo.AddValue("_UseDefaultCredentials", this.UseDefaultCredentials);
}
// Token: 0x06001707 RID: 5895 RVA: 0x0004D968 File Offset: 0x0004BB68
private void CheckBypassList()
{
if (this.bypassList == null)
{
return;
}
for (int i = 0; i < this.bypassList.Count; i++)
{
new global::System.Text.RegularExpressions.Regex((string)this.bypassList[i]);
}
}
// Token: 0x06001708 RID: 5896 RVA: 0x0004D9B4 File Offset: 0x0004BBB4
private static global::System.Uri ToUri(string address)
{
if (address == null)
{
return null;
}
if (address.IndexOf("://") == -1)
{
address = "http://" + address;
}
return new global::System.Uri(address);
}
// Token: 0x0400127E RID: 4734
private global::System.Uri address;
// Token: 0x0400127F RID: 4735
private bool bypassOnLocal;
// Token: 0x04001280 RID: 4736
private ArrayList bypassList;
// Token: 0x04001281 RID: 4737
private ICredentials credentials;
// Token: 0x04001282 RID: 4738
private bool useDefaultCredentials;
}
}