Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpWindowsProxy.cs
Go to the documentation of this file.
6using System.Text;
7
8namespace System.Net.Http;
9
11{
12 private readonly MultiProxy _insecureProxy;
13
14 private readonly MultiProxy _secureProxy;
15
17
18 private readonly List<string> _bypass;
19
20 private readonly bool _bypassLocal;
21
22 private readonly List<IPAddress> _localIp;
23
25
27
28 private global::Interop.WinHttp.SafeWinHttpHandle _sessionHandle;
29
30 private bool _disposed;
31
33 {
34 get
35 {
36 return _credentials;
37 }
38 set
39 {
41 }
42 }
43
44 public static bool TryCreate([NotNullWhen(true)] out IWebProxy proxy)
45 {
46 global::Interop.WinHttp.SafeWinHttpHandle safeWinHttpHandle = null;
47 proxy = null;
49 if (!winInetProxyHelper.ManualSettingsOnly && !winInetProxyHelper.AutoSettingsUsed)
50 {
51 return false;
52 }
53 if (winInetProxyHelper.AutoSettingsUsed)
54 {
55 if (System.Net.NetEventSource.Log.IsEnabled())
56 {
57 System.Net.NetEventSource.Info(winInetProxyHelper, FormattableStringFactory.Create("AutoSettingsUsed, calling {0}", "WinHttpOpen"), "TryCreate");
58 }
59 safeWinHttpHandle = global::Interop.WinHttp.WinHttpOpen(IntPtr.Zero, 1u, null, null, 268435456);
60 if (safeWinHttpHandle.IsInvalid)
61 {
62 if (System.Net.NetEventSource.Log.IsEnabled())
63 {
64 System.Net.NetEventSource.Error(winInetProxyHelper, FormattableStringFactory.Create("{0} returned invalid handle", "WinHttpOpen"), "TryCreate");
65 }
66 return false;
67 }
68 }
70 return true;
71 }
72
73 private HttpWindowsProxy(WinInetProxyHelper proxyHelper, global::Interop.WinHttp.SafeWinHttpHandle sessionHandle)
74 {
77 if (!proxyHelper.ManualSettingsUsed)
78 {
79 return;
80 }
81 if (System.Net.NetEventSource.Log.IsEnabled())
82 {
83 System.Net.NetEventSource.Info(proxyHelper, $"ManualSettingsUsed, {proxyHelper.Proxy}", ".ctor");
84 }
87 if (!string.IsNullOrWhiteSpace(proxyHelper.ProxyBypass))
88 {
89 int i = 0;
90 int num = 0;
91 _bypass = new List<string>(proxyHelper.ProxyBypass.Length / 5);
92 while (i < proxyHelper.ProxyBypass.Length)
93 {
94 for (; i < proxyHelper.ProxyBypass.Length && proxyHelper.ProxyBypass[i] == ' '; i++)
95 {
96 }
97 if (string.Compare(proxyHelper.ProxyBypass, i, "http://", 0, 7, StringComparison.OrdinalIgnoreCase) == 0)
98 {
99 i += 7;
100 }
101 else if (string.Compare(proxyHelper.ProxyBypass, i, "https://", 0, 8, StringComparison.OrdinalIgnoreCase) == 0)
102 {
103 i += 8;
104 }
105 if (i < proxyHelper.ProxyBypass.Length && proxyHelper.ProxyBypass[i] == '[')
106 {
107 i++;
108 }
109 num = i;
110 for (; i < proxyHelper.ProxyBypass.Length && proxyHelper.ProxyBypass[i] != ' ' && proxyHelper.ProxyBypass[i] != ';' && proxyHelper.ProxyBypass[i] != ']'; i++)
111 {
112 }
113 string text;
114 if (i == num)
115 {
116 text = null;
117 }
118 else if (string.Compare(proxyHelper.ProxyBypass, num, "<local>", 0, 7, StringComparison.OrdinalIgnoreCase) == 0)
119 {
120 _bypassLocal = true;
121 text = null;
122 }
123 else
124 {
125 text = proxyHelper.ProxyBypass.Substring(num, i - num);
126 }
127 if (i < proxyHelper.ProxyBypass.Length && proxyHelper.ProxyBypass[i] != ';')
128 {
129 for (; i < proxyHelper.ProxyBypass.Length && proxyHelper.ProxyBypass[i] != ';'; i++)
130 {
131 }
132 }
133 if (i < proxyHelper.ProxyBypass.Length && proxyHelper.ProxyBypass[i] == ';')
134 {
135 i++;
136 }
137 if (text != null)
138 {
140 }
141 }
142 if (_bypass.Count == 0)
143 {
144 _bypass = null;
145 }
146 }
147 if (!_bypassLocal)
148 {
149 return;
150 }
154 {
156 foreach (UnicastIPAddressInformation unicastAddress in iPProperties.UnicastAddresses)
157 {
158 _localIp.Add(unicastAddress.Address);
159 }
160 }
161 }
162
163 public void Dispose()
164 {
165 if (!_disposed)
166 {
167 _disposed = true;
168 if (_sessionHandle != null && !_sessionHandle.IsInvalid)
169 {
170 global::Interop.WinHttp.SafeWinHttpHandle.DisposeAndClearHandle(ref _sessionHandle);
171 }
172 }
173 }
174
175 public Uri GetProxy(Uri uri)
176 {
178 return uri2;
179 }
180
182 {
184 {
185 global::Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo = default(global::Interop.WinHttp.WINHTTP_PROXY_INFO);
186 try
187 {
189 {
190 return MultiProxy.Empty;
191 }
192 if (proxyInfo.ProxyBypass == IntPtr.Zero)
193 {
194 if (proxyInfo.Proxy != IntPtr.Zero)
195 {
198 }
199 return MultiProxy.Empty;
200 }
201 }
202 finally
203 {
205 Marshal.FreeHGlobal(proxyInfo.ProxyBypass);
206 }
207 }
209 {
210 if (_bypassLocal)
211 {
212 if (uri.IsLoopback)
213 {
214 return MultiProxy.Empty;
215 }
216 if ((uri.HostNameType == UriHostNameType.IPv6 || uri.HostNameType == UriHostNameType.IPv4) && IPAddress.TryParse(uri.IdnHost, out IPAddress address))
217 {
218 foreach (IPAddress item in _localIp)
219 {
220 if (item.Equals(address))
221 {
222 return MultiProxy.Empty;
223 }
224 }
225 }
226 if (uri.HostNameType != UriHostNameType.IPv6 && !uri.IdnHost.Contains('.'))
227 {
228 return MultiProxy.Empty;
229 }
230 }
231 if (_bypass != null)
232 {
233 foreach (string item2 in _bypass)
234 {
236 {
237 return MultiProxy.Empty;
238 }
239 }
240 }
241 if (!IsSecureUri(uri))
242 {
243 return _insecureProxy;
244 }
245 return _secureProxy;
246 }
247 return MultiProxy.Empty;
248 }
249
250 private static bool IsSecureUri(Uri uri)
251 {
252 if (!(uri.Scheme == "https"))
253 {
254 return uri.Scheme == "wss";
255 }
256 return true;
257 }
258
259 public bool IsBypassed(Uri uri)
260 {
261 return false;
262 }
263}
void Add(TKey key, TValue value)
readonly WinInetProxyHelper _proxyHelper
HttpWindowsProxy(WinInetProxyHelper proxyHelper, global::Interop.WinHttp.SafeWinHttpHandle sessionHandle)
readonly List< string > _bypass
readonly List< IPAddress > _localIp
static bool TryCreate([NotNullWhen(true)] out IWebProxy proxy)
global::Interop.WinHttp.SafeWinHttpHandle _sessionHandle
readonly FailedProxyCache _failedProxies
bool GetProxyForUrl(global::Interop.WinHttp.SafeWinHttpHandle sessionHandle, Uri uri, out global::Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo)
static bool TryParse([NotNullWhen(true)] string? ipString, [NotNullWhen(true)] out IPAddress? address)
Definition IPAddress.cs:303
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static NetworkInterface[] GetAllNetworkInterfaces()
static FormattableString Create(string format, params object?[] arguments)
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition Marshal.cs:652
static bool IsMatchWithStarWildcard(ReadOnlySpan< char > input, ReadOnlySpan< char > pattern)
Definition SimpleRegex.cs:5
string IdnHost
Definition Uri.cs:537
bool IsLoopback
Definition Uri.cs:365
UriHostNameType HostNameType
Definition Uri.cs:304
string Scheme
Definition Uri.cs:505
static readonly IntPtr Zero
Definition IntPtr.cs:18
static MultiProxy CreateLazy(FailedProxyCache failedProxyCache, string proxyConfig, bool secure)
Definition MultiProxy.cs:59
static MultiProxy Empty
Definition MultiProxy.cs:21
bool ReadNext([NotNullWhen(true)] out Uri uri, out bool isFinalProxy)
Definition MultiProxy.cs:68
static MultiProxy Parse(FailedProxyCache failedProxyCache, string proxyConfig, bool secure)
Definition MultiProxy.cs:43