|
| 1 | +using BaGet.Core.Configuration; |
| 2 | + |
1 | 3 | namespace BaGet.Core; |
2 | 4 |
|
3 | 5 | public static partial class DependencyInjectionExtensions |
@@ -50,6 +52,7 @@ private static void AddConfiguration(this IServiceCollection services) |
50 | 52 | services.AddBaGetOptions<DatabaseOptions>(nameof(BaGetOptions.Database)); |
51 | 53 | services.AddBaGetOptions<FileSystemStorageOptions>(nameof(BaGetOptions.Storage)); |
52 | 54 | services.AddBaGetOptions<MirrorOptions>(nameof(BaGetOptions.Mirror)); |
| 55 | + services.AddBaGetOptions<ProxyOptions>(nameof(BaGetOptions.Proxy)); |
53 | 56 | services.AddBaGetOptions<SearchOptions>(nameof(BaGetOptions.Search)); |
54 | 57 | services.AddBaGetOptions<StorageOptions>(nameof(BaGetOptions.Storage)); |
55 | 58 | } |
@@ -159,10 +162,19 @@ private static HttpClient HttpClientFactory(IServiceProvider provider) |
159 | 162 | var assemblyName = assembly.GetName().Name; |
160 | 163 | var assemblyVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "0.0.0"; |
161 | 164 |
|
162 | | - var client = new HttpClient(new HttpClientHandler |
| 165 | + var httpClientHandler = new HttpClientHandler |
163 | 166 | { |
164 | 167 | AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, |
165 | | - }); |
| 168 | + }; |
| 169 | + |
| 170 | + var proxyOptions = provider.GetRequiredService<IOptions<ProxyOptions>>(); |
| 171 | + |
| 172 | + if (!string.IsNullOrEmpty(proxyOptions.Value.Address)) |
| 173 | + { |
| 174 | + httpClientHandler.Proxy = new System.Net.WebProxy(proxyOptions.Value.Address); |
| 175 | + } |
| 176 | + |
| 177 | + var client = new HttpClient(httpClientHandler); |
166 | 178 |
|
167 | 179 | client.DefaultRequestHeaders.Add("User-Agent", $"{assemblyName}/{assemblyVersion}"); |
168 | 180 | client.Timeout = TimeSpan.FromSeconds(options.PackageDownloadTimeoutSeconds); |
|
0 commit comments