Skip to content

Commit ad9d504

Browse files
committed
fix(Proxy): 没有系统代理时会获取到错误的系统代理
1 parent 9c97f1f commit ad9d504

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Plain Craft Launcher 2/Modules/Base/ModNet.vb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@
66
''' </summary>
77
''' <returns>返回 WebProxy 或者 Nothing</returns>
88
Public Function GetProxy()
9-
Dim proxy As String = Setup.Get("SystemHttpProxy")
10-
Dim SystemProxy As New WebProxy(WebRequest.GetSystemWebProxy().GetProxy(New Uri("https://www.example.com")))
11-
If SystemProxy IsNot Nothing AndAlso Setup.Get("SystemUseDefaultProxy") Then
12-
Log("[Net] 当前代理状态:跟随系统代理设置")
13-
Return SystemProxy
9+
Dim ProxyServer As String = Setup.Get("SystemHttpProxy")
10+
Dim SystemProxyServer As String = WebRequest.GetSystemWebProxy().GetProxy(New Uri("https://www.example.com/")).ToString
11+
If SystemProxyServer.Equals("https://www.example.com/") Then '没有系统代理的情况下会返回原始 Uri,这导致了使用此方法获取系统代理的网络请求全部炸掉
12+
Log("[Net] 检测到未设置系统代理,已忽略系统代理")
13+
ElseIf Not SystemProxyServer.StartsWithF("http:") Then
14+
Log("[Net] 检测到不支持的代理服务器协议,已忽略系统代理")
15+
Else
16+
Dim SystemProxy As New WebProxy(New Uri(SystemProxyServer))
17+
If SystemProxy IsNot Nothing AndAlso Setup.Get("SystemUseDefaultProxy") Then
18+
Log("[Net] 当前代理状态:跟随系统代理设置")
19+
Return SystemProxy
20+
End If
1421
End If
15-
If Not String.IsNullOrWhiteSpace(proxy) AndAlso Not Setup.Get("SystemUseDefaultProxy") Then
22+
If Not String.IsNullOrWhiteSpace(ProxyServer) Then
1623
Log("[Net] 当前代理状态:自定义")
17-
Dim ProxyUri As New Uri(proxy)
24+
Dim ProxyUri As New Uri(ProxyServer)
1825
Try
26+
If Not ProxyUri.Scheme.ContainsF("http:") Then Return Nothing
1927
If ProxyUri.IsLoopback OrElse
2028
ProxyUri.Host.StartsWithF("192.168.") OrElse
2129
ProxyUri.Host.StartsWithF("10.") OrElse
@@ -24,7 +32,7 @@
2432
'视作非本地地址
2533
Catch
2634
End Try
27-
Return New WebProxy(proxy, True)
35+
Return New WebProxy(ProxyServer, True)
2836
End If
2937
Log("[Net] 当前代理状态:禁用")
3038
Return Nothing

0 commit comments

Comments
 (0)