Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WebProxy.cs
Go to the documentation of this file.
9
10namespace System.Net;
11
13{
15
17
18 private static volatile string s_domainName;
19
20 private static volatile IPAddress[] s_localAddresses;
21
22 private static int s_networkChangeRegistered;
23
24 public Uri? Address { get; set; }
25
26 public bool BypassProxyOnLocal { get; set; }
27
28 public string[] BypassList
29 {
30 get
31 {
32 if (_bypassList == null)
33 {
34 return Array.Empty<string>();
35 }
36 string[] array = new string[_bypassList.Count];
38 return array;
39 }
41 set
42 {
43 _bypassList = ((value != null) ? new ArrayList(value) : null);
45 }
46 }
47
49
50 public ICredentials? Credentials { get; set; }
51
53 {
54 get
55 {
57 }
58 set
59 {
61 }
62 }
63
64 public WebProxy()
66 {
67 }
68
71 {
72 }
73
76 {
77 }
78
79 public WebProxy(Uri? Address, bool BypassOnLocal, string[]? BypassList)
81 {
82 }
83
95
96 public WebProxy(string Host, int Port)
97 {
100 handler.AppendLiteral("http://");
101 handler.AppendFormatted(Host);
102 handler.AppendLiteral(":");
103 handler.AppendFormatted(Port);
104 this._002Ector(new Uri(string.Create(invariantCulture, ref handler)), BypassOnLocal: false, null, null);
105 }
106
107 public WebProxy(string? Address)
109 {
110 }
111
112 public WebProxy(string? Address, bool BypassOnLocal)
114 {
115 }
116
117 public WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList)
119 {
120 }
121
126
128 {
129 if (destination == null)
130 {
131 throw new ArgumentNullException("destination");
132 }
134 {
135 return Address;
136 }
137 return destination;
138 }
139
140 private static Uri CreateProxyUri(string address)
141 {
142 if (address != null)
143 {
144 if (address.Contains("://"))
145 {
146 return new Uri(address);
147 }
148 return new Uri("http://" + address);
149 }
150 return null;
151 }
152
153 private void UpdateRegexList(bool canThrow)
154 {
155 Regex[] array = null;
157 try
158 {
159 if (bypassList != null && bypassList.Count > 0)
160 {
161 array = new Regex[bypassList.Count];
162 for (int i = 0; i < bypassList.Count; i++)
163 {
164 array[i] = new Regex((string)bypassList[i], RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
165 }
166 }
167 }
168 catch
169 {
170 if (!canThrow)
171 {
172 _regexBypassList = null;
173 return;
174 }
175 throw;
176 }
178 }
179
181 {
183 if (_regexBypassList != null)
184 {
185 Span<char> span = stackalloc char[128];
186 string text;
187 if (!input.IsDefaultPort)
188 {
194 handler.AppendFormatted(input.Scheme);
195 handler.AppendLiteral("://");
196 handler.AppendFormatted(input.Host);
197 handler.AppendLiteral(":");
198 handler.AppendFormatted((uint)input.Port);
199 text = string.Create(provider, initialBuffer, ref handler);
200 }
201 else
202 {
208 handler2.AppendFormatted(input.Scheme);
209 handler2.AppendLiteral("://");
210 handler2.AppendFormatted(input.Host);
211 text = string.Create(provider2, initialBuffer2, ref handler2);
212 }
213 string input2 = text;
215 foreach (Regex regex in regexBypassList)
216 {
217 if (regex.IsMatch(input2))
218 {
219 return true;
220 }
221 }
222 }
223 return false;
224 }
225
226 public bool IsBypassed(Uri host)
227 {
228 if (host == null)
229 {
230 throw new ArgumentNullException("host");
231 }
232 if (!(Address == null) && (!BypassProxyOnLocal || !IsLocal(host)))
233 {
235 }
236 return true;
237 }
238
243
248
253
254 [Obsolete("WebProxy.GetDefaultProxy has been deprecated. Use the proxy selected for you by default.")]
255 public static WebProxy GetDefaultProxy()
256 {
258 }
259
260 private bool IsLocal(Uri host)
261 {
262 if (host.IsLoopback)
263 {
264 return true;
265 }
266 string host2 = host.Host;
267 if (IPAddress.TryParse(host2, out IPAddress address))
268 {
271 return Array.IndexOf(array, address) != -1;
272 }
273 int num = host2.IndexOf('.');
274 if (num == -1)
275 {
276 return true;
277 }
279 string text = s_domainName ?? (s_domainName = "." + IPGlobalProperties.GetIPGlobalProperties().DomainName);
280 if (text.Length == host2.Length - num)
281 {
282 return string.Compare(text, 0, host2, num, text.Length, StringComparison.OrdinalIgnoreCase) == 0;
283 }
284 return false;
285 }
286
288 {
290 {
291 Register();
292 }
293 static void Register()
294 {
296 {
298 {
299 s_domainName = null;
300 s_localAddresses = null;
301 };
303 {
304 s_domainName = null;
305 s_localAddresses = null;
306 };
307 }
308 }
309 }
310}
int IList. IndexOf(object value)
Definition Array.cs:1228
virtual void CopyTo(Array array)
static CultureInfo InvariantCulture
static ICredentials DefaultCredentials
static string GetHostName()
Definition Dns.cs:16
static IPHostEntry GetHostEntry(IPAddress address)
Definition Dns.cs:36
static bool TryParse([NotNullWhen(true)] string? ipString, [NotNullWhen(true)] out IPAddress? address)
Definition IPAddress.cs:303
static volatile string s_domainName
Definition WebProxy.cs:18
static void EnsureNetworkChangeRegistration()
Definition WebProxy.cs:287
WebProxy(string? Address, bool BypassOnLocal)
Definition WebProxy.cs:112
Regex[] _regexBypassList
Definition WebProxy.cs:16
WebProxy(Uri? Address, bool BypassOnLocal)
Definition WebProxy.cs:74
bool UseDefaultCredentials
Definition WebProxy.cs:53
virtual void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
Definition WebProxy.cs:249
WebProxy(string? Address)
Definition WebProxy.cs:107
WebProxy(Uri? Address)
Definition WebProxy.cs:69
bool IsLocal(Uri host)
Definition WebProxy.cs:260
bool IsMatchInBypassList(Uri input)
Definition WebProxy.cs:180
string[] BypassList
Definition WebProxy.cs:29
ArrayList BypassArrayList
Definition WebProxy.cs:48
WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList)
Definition WebProxy.cs:117
WebProxy(string Host, int Port)
Definition WebProxy.cs:96
WebProxy(Uri? Address, bool BypassOnLocal, string[]? BypassList, ICredentials? Credentials)
Definition WebProxy.cs:84
void UpdateRegexList(bool canThrow)
Definition WebProxy.cs:153
WebProxy(string? Address, bool BypassOnLocal, string[]? BypassList, ICredentials? Credentials)
Definition WebProxy.cs:122
ArrayList _bypassList
Definition WebProxy.cs:14
bool IsBypassed(Uri host)
Definition WebProxy.cs:226
static Uri CreateProxyUri(string address)
Definition WebProxy.cs:140
WebProxy(Uri? Address, bool BypassOnLocal, string[]? BypassList)
Definition WebProxy.cs:79
static WebProxy GetDefaultProxy()
Definition WebProxy.cs:255
static volatile IPAddress[] s_localAddresses
Definition WebProxy.cs:20
ICredentials? Credentials
Definition WebProxy.cs:50
Uri? GetProxy(Uri destination)
Definition WebProxy.cs:127
static int s_networkChangeRegistered
Definition WebProxy.cs:22
WebProxy(SerializationInfo serializationInfo, StreamingContext streamingContext)
Definition WebProxy.cs:239
static int Exchange(ref int location1, int value)
void GetObjectData(SerializationInfo info, StreamingContext context)