Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetProxyForUrl()

bool System.Net.Http.WinInetProxyHelper.GetProxyForUrl ( global::Interop::WinHttp::SafeWinHttpHandle sessionHandle,
Uri uri,
out global::Interop::WinHttp::WINHTTP_PROXY_INFO proxyInfo )
inline

Definition at line 106 of file WinInetProxyHelper.cs.

107 {
108 proxyInfo.AccessType = 1u;
109 proxyInfo.Proxy = IntPtr.Zero;
110 proxyInfo.ProxyBypass = IntPtr.Zero;
111 if (!_useProxy)
112 {
113 return false;
114 }
115 bool flag = false;
116 Unsafe.SkipInit(out global::Interop.WinHttp.WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions);
117 autoProxyOptions.AutoConfigUrl = AutoConfigUrl;
118 autoProxyOptions.AutoDetectFlags = (AutoDetect ? 3u : 0u);
119 autoProxyOptions.AutoLoginIfChallenged = false;
120 autoProxyOptions.Flags = (AutoDetect ? 1u : 0u) | ((!string.IsNullOrEmpty(AutoConfigUrl)) ? 2u : 0u);
121 autoProxyOptions.Reserved1 = IntPtr.Zero;
122 autoProxyOptions.Reserved2 = 0u;
123 string text = uri.AbsoluteUri;
124 if (uri.Scheme == "wss")
125 {
126 text = "https" + text.Substring("wss".Length);
127 }
128 else if (uri.Scheme == "ws")
129 {
130 text = "http" + text.Substring("ws".Length);
131 }
132 bool flag2 = false;
133 do
134 {
135 _autoDetectionFailed = false;
136 if (global::Interop.WinHttp.WinHttpGetProxyForUrl(sessionHandle, text, ref autoProxyOptions, out proxyInfo))
137 {
138 if (System.Net.NetEventSource.Log.IsEnabled())
139 {
140 System.Net.NetEventSource.Info(this, "Using autoconfig proxy settings", "GetProxyForUrl");
141 }
142 flag = true;
143 break;
144 }
145 int lastWin32Error = Marshal.GetLastWin32Error();
146 if (System.Net.NetEventSource.Log.IsEnabled())
147 {
148 System.Net.NetEventSource.Error(this, $"error={lastWin32Error}", "GetProxyForUrl");
149 }
150 if ((long)lastWin32Error == 12015)
151 {
152 if (flag2)
153 {
154 break;
155 }
156 flag2 = true;
157 autoProxyOptions.AutoLoginIfChallenged = true;
158 continue;
159 }
160 if ((long)lastWin32Error == 12180)
161 {
163 _lastTimeAutoDetectionFailed = Environment.TickCount;
164 }
165 break;
166 }
167 while (flag2);
168 if (!flag && !string.IsNullOrEmpty(Proxy))
169 {
170 proxyInfo.AccessType = 3u;
171 proxyInfo.Proxy = Marshal.StringToHGlobalUni(Proxy);
172 proxyInfo.ProxyBypass = (string.IsNullOrEmpty(ProxyBypass) ? IntPtr.Zero : Marshal.StringToHGlobalUni(ProxyBypass));
173 if (System.Net.NetEventSource.Log.IsEnabled())
174 {
175 System.Net.NetEventSource.Info(this, $"Fallback to Proxy={Proxy}, ProxyBypass={ProxyBypass}", "GetProxyForUrl");
176 }
177 flag = true;
178 }
179 if (System.Net.NetEventSource.Log.IsEnabled())
180 {
181 System.Net.NetEventSource.Info(this, $"useProxy={flag}", "GetProxyForUrl");
182 }
183 return flag;
184 }
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 unsafe IntPtr StringToHGlobalUni(string? s)
Definition Marshal.cs:1310

References System.Net.Http.WinInetProxyHelper._autoDetectionFailed, System.Net.Http.WinInetProxyHelper._lastTimeAutoDetectionFailed, System.Net.Http.WinInetProxyHelper._useProxy, System.Uri.AbsoluteUri, System.Net.Http.WinInetProxyHelper.AutoConfigUrl, System.Net.Http.WinInetProxyHelper.AutoDetect, System.Net.NetEventSource.Error(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), System.Net.NetEventSource.Info(), System.Net.NetEventSource.Log, System.Net.Http.WinInetProxyHelper.Proxy, System.Net.Http.WinInetProxyHelper.ProxyBypass, System.Uri.Scheme, System.Runtime.InteropServices.Marshal.StringToHGlobalUni(), System.text, System.Environment.TickCount, and System.IntPtr.Zero.

Referenced by System.Net.Http.HttpWindowsProxy.GetMultiProxy().