Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/BaGet.Core/Configuration/BaGetOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.ComponentModel.DataAnnotations;
using BaGet.Core.Configuration;

namespace BaGet.Core
{
Expand Down Expand Up @@ -50,5 +50,7 @@ public class BaGetOptions
public SearchOptions Search { get; set; }

public MirrorOptions Mirror { get; set; }

public ProxyOptions Proxy { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/BaGet.Core/Configuration/ProxyOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.ComponentModel.DataAnnotations;

namespace BaGet.Core.Configuration
{
public class ProxyOptions
{
public string Address { get; set; }
}
}
17 changes: 14 additions & 3 deletions src/BaGet.Core/Extensions/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
using System.Net;
using System.Net.Http;
using System.Reflection;
using BaGet.Protocol;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using BaGet.Core.Configuration;
using BaGet.Protocol;

namespace BaGet.Core
{
Expand Down Expand Up @@ -65,6 +66,7 @@ private static void AddConfiguration(this IServiceCollection services)
services.AddBaGetOptions<DatabaseOptions>(nameof(BaGetOptions.Database));
services.AddBaGetOptions<FileSystemStorageOptions>(nameof(BaGetOptions.Storage));
services.AddBaGetOptions<MirrorOptions>(nameof(BaGetOptions.Mirror));
services.AddBaGetOptions<ProxyOptions>(nameof(BaGetOptions.Proxy));
services.AddBaGetOptions<SearchOptions>(nameof(BaGetOptions.Search));
services.AddBaGetOptions<StorageOptions>(nameof(BaGetOptions.Storage));
}
Expand Down Expand Up @@ -174,10 +176,19 @@ private static HttpClient HttpClientFactory(IServiceProvider provider)
var assemblyName = assembly.GetName().Name;
var assemblyVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "0.0.0";

var client = new HttpClient(new HttpClientHandler
var httpClientHandler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
});
};

var proxyOptions = provider.GetRequiredService<IOptions<ProxyOptions>>();

if (!string.IsNullOrEmpty(proxyOptions.Value.Address))
{
httpClientHandler.Proxy = new WebProxy(proxyOptions.Value.Address);
}

var client = new HttpClient(httpClientHandler);

client.DefaultRequestHeaders.Add("User-Agent", $"{assemblyName}/{assemblyVersion}");
client.Timeout = TimeSpan.FromSeconds(options.PackageDownloadTimeoutSeconds);
Expand Down