Skip to content

Commit ff5fd57

Browse files
taoocerosjjw24
authored andcommitted
fix potential uri format issue causing program crash
1 parent cc48ed5 commit ff5fd57

File tree

1 file changed

+25
-15
lines changed
  • Flow.Launcher.Infrastructure/Http

1 file changed

+25
-15
lines changed

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,35 @@ public static HttpProxy Proxy
5050
/// </summary>
5151
public static void UpdateProxy(ProxyProperty property)
5252
{
53-
(WebProxy.Address, WebProxy.Credentials) = property switch
53+
if (string.IsNullOrEmpty(Proxy.Server))
54+
return;
55+
56+
try
5457
{
55-
ProxyProperty.Enabled => Proxy.Enabled switch
58+
(WebProxy.Address, WebProxy.Credentials) = property switch
5659
{
57-
true => Proxy.UserName switch
60+
ProxyProperty.Enabled => Proxy.Enabled switch
5861
{
59-
var userName when !string.IsNullOrEmpty(userName) =>
60-
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
61-
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
62-
new NetworkCredential(Proxy.UserName, Proxy.Password))
62+
true when !string.IsNullOrEmpty(Proxy.Server) => Proxy.UserName switch
63+
{
64+
var userName when string.IsNullOrEmpty(userName) =>
65+
(new Uri($"http://{Proxy.Server}:{Proxy.Port}"), null),
66+
_ => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"),
67+
new NetworkCredential(Proxy.UserName, Proxy.Password))
68+
},
69+
_ => (null, null)
6370
},
64-
false => (null, null)
65-
},
66-
ProxyProperty.Server => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
67-
ProxyProperty.Port => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
68-
ProxyProperty.UserName => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
69-
ProxyProperty.Password => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
70-
_ => throw new ArgumentOutOfRangeException()
71-
};
71+
ProxyProperty.Server => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
72+
ProxyProperty.Port => (new Uri($"http://{Proxy.Server}:{Proxy.Port}"), WebProxy.Credentials),
73+
ProxyProperty.UserName => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
74+
ProxyProperty.Password => (WebProxy.Address, new NetworkCredential(Proxy.UserName, Proxy.Password)),
75+
_ => throw new ArgumentOutOfRangeException()
76+
};
77+
}
78+
catch(UriFormatException e)
79+
{
80+
Log.Exception("Http", "Unable to parse Uri", e);
81+
}
7282
}
7383

7484
public static async Task DownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default)

0 commit comments

Comments
 (0)