@@ -50,25 +50,35 @@ public static HttpProxy Proxy
50
50
/// </summary>
51
51
public static void UpdateProxy ( ProxyProperty property )
52
52
{
53
- ( WebProxy . Address , WebProxy . Credentials ) = property switch
53
+ if ( string . IsNullOrEmpty ( Proxy . Server ) )
54
+ return ;
55
+
56
+ try
54
57
{
55
- ProxyProperty . Enabled => Proxy . Enabled switch
58
+ ( WebProxy . Address , WebProxy . Credentials ) = property switch
56
59
{
57
- true => Proxy . UserName switch
60
+ ProxyProperty . Enabled => Proxy . Enabled switch
58
61
{
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 )
63
70
} ,
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
+ }
72
82
}
73
83
74
84
public static async Task DownloadAsync ( [ NotNull ] string url , [ NotNull ] string filePath , CancellationToken token = default )
0 commit comments