Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpEnvironmentProxy.cs
Go to the documentation of this file.
2
3namespace System.Net.Http;
4
5internal sealed class HttpEnvironmentProxy : IWebProxy
6{
7 private readonly Uri _httpProxyUri;
8
9 private readonly Uri _httpsProxyUri;
10
11 private readonly string[] _bypass;
12
14
16 {
17 get
18 {
19 return _credentials;
20 }
21 set
22 {
24 }
25 }
26
27 private HttpEnvironmentProxy(Uri httpProxy, Uri httpsProxy, string bypassList)
28 {
29 _httpProxyUri = httpProxy;
30 _httpsProxyUri = httpsProxy;
32 _bypass = bypassList?.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
33 }
34
35 private static Uri GetUriFromString(string value)
36 {
37 if (string.IsNullOrEmpty(value))
38 {
39 return null;
40 }
41 if (value.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
42 {
43 value = value.Substring(7);
44 }
45 string text = null;
46 string text2 = null;
47 ushort result = 80;
48 int num = value.LastIndexOf('@');
49 if (num != -1)
50 {
51 string text3 = value.Substring(0, num);
52 try
53 {
54 text3 = Uri.UnescapeDataString(text3);
55 }
56 catch
57 {
58 }
59 value = value.Substring(num + 1);
60 num = text3.IndexOf(':');
61 if (num == -1)
62 {
63 text = text3;
64 }
65 else
66 {
67 text = text3.Substring(0, num);
68 text2 = text3.Substring(num + 1);
69 }
70 }
71 int num2 = value.IndexOf(']');
72 num = value.LastIndexOf(':');
73 string host;
74 if (num == -1 || (num2 != -1 && num < num2))
75 {
76 host = value;
77 }
78 else
79 {
80 host = value.Substring(0, num);
81 int i;
82 for (i = num + 1; i < value.Length && char.IsDigit(value[i]); i++)
83 {
84 }
85 if (!ushort.TryParse(value.AsSpan(num + 1, i - num - 1), out result))
86 {
87 return null;
88 }
89 }
90 try
91 {
92 UriBuilder uriBuilder = new UriBuilder("http", host, result);
93 if (text != null)
94 {
95 uriBuilder.UserName = Uri.EscapeDataString(text);
96 }
97 if (text2 != null)
98 {
99 uriBuilder.Password = Uri.EscapeDataString(text2);
100 }
101 return uriBuilder.Uri;
102 }
103 catch
104 {
105 }
106 return null;
107 }
108
110 {
111 if (_bypass != null)
112 {
113 string[] bypass = _bypass;
114 foreach (string text in bypass)
115 {
116 if (text[0] == '.')
117 {
118 if (text.Length - 1 == input.Host.Length && string.Compare(text, 1, input.Host, 0, input.Host.Length, StringComparison.OrdinalIgnoreCase) == 0)
119 {
120 return true;
121 }
122 if (input.Host.EndsWith(text, StringComparison.OrdinalIgnoreCase))
123 {
124 return true;
125 }
126 }
127 else if (string.Equals(text, input.Host, StringComparison.OrdinalIgnoreCase))
128 {
129 return true;
130 }
131 }
132 }
133 return false;
134 }
135
136 public Uri GetProxy(Uri uri)
137 {
139 {
140 return _httpsProxyUri;
141 }
142 return _httpProxyUri;
143 }
144
145 public bool IsBypassed(Uri uri)
146 {
147 if (!(GetProxy(uri) == null))
148 {
149 return IsMatchInBypassList(uri);
150 }
151 return true;
152 }
153
154 public static bool TryCreate([NotNullWhen(true)] out IWebProxy proxy)
155 {
156 Uri uri = null;
157 if (Environment.GetEnvironmentVariable("GATEWAY_INTERFACE") == null)
158 {
160 }
162 if (uri == null || uri2 == null)
163 {
164 Uri uriFromString = GetUriFromString(Environment.GetEnvironmentVariable("ALL_PROXY"));
165 if (uri == null)
166 {
167 uri = uriFromString;
168 }
169 if (uri2 == null)
170 {
171 uri2 = uriFromString;
172 }
173 }
174 if (uri == null && uri2 == null)
175 {
176 proxy = null;
177 return false;
178 }
179 string environmentVariable = Environment.GetEnvironmentVariable("NO_PROXY");
180 proxy = new HttpEnvironmentProxy(uri, uri2, environmentVariable);
181 return true;
182 }
183}
static ? string GetEnvironmentVariable(string variable)
static HttpEnvironmentProxyCredentials TryCreate(Uri httpProxy, Uri httpsProxy)
HttpEnvironmentProxy(Uri httpProxy, Uri httpsProxy, string bypassList)
static bool TryCreate([NotNullWhen(true)] out IWebProxy proxy)
static bool IsSupportedNonSecureScheme(string scheme)
static string EscapeDataString(string stringToEscape)
Definition Uri.cs:4087
static string UnescapeDataString(string stringToUnescape)
Definition Uri.cs:4058
string Scheme
Definition Uri.cs:505