Support for proxying requests through OpenCache

pull/151/head
Ryan Kistner 5 years ago
parent 30312af050
commit 618090e23d

@ -18,6 +18,7 @@ namespace DepotDownloader
private readonly Steam3Session steamSession; private readonly Steam3Session steamSession;
private readonly uint appId; private readonly uint appId;
private CDNClient.Server proxyServer;
public CDNClient CDNClient { get; } public CDNClient CDNClient { get; }
@ -29,11 +30,29 @@ namespace DepotDownloader
private readonly CancellationTokenSource shutdownToken; private readonly CancellationTokenSource shutdownToken;
public CancellationTokenSource ExhaustedToken { get; set; } public CancellationTokenSource ExhaustedToken { get; set; }
#if STEAMKIT_UNRELEASED
private UriBuilder TransformCdnClientRequest(UriBuilder uriBuilder)
{
if (proxyServer != null)
{
var pathTemplate = proxyServer.ProxyRequestPathTemplate;
pathTemplate = pathTemplate.Replace("%host%", uriBuilder.Host);
pathTemplate = pathTemplate.Replace("%path%", $"/{uriBuilder.Path}");
uriBuilder.Scheme = proxyServer.Protocol == CDNClient.Server.ConnectionProtocol.HTTP ? "http" : "https";
uriBuilder.Host = proxyServer.VHost;
uriBuilder.Port = proxyServer.Port;
uriBuilder.Path = pathTemplate;
}
return uriBuilder;
}
#endif
public CDNClientPool(Steam3Session steamSession, uint appId) public CDNClientPool(Steam3Session steamSession, uint appId)
{ {
this.steamSession = steamSession; this.steamSession = steamSession;
this.appId = appId; this.appId = appId;
CDNClient = new CDNClient(steamSession.steamClient); CDNClient = new CDNClient(steamSession.steamClient, TransformCdnClientRequest);
activeConnectionPool = new ConcurrentStack<CDNClient.Server>(); activeConnectionPool = new ConcurrentStack<CDNClient.Server>();
availableServerEndpoints = new BlockingCollection<CDNClient.Server>(); availableServerEndpoints = new BlockingCollection<CDNClient.Server>();
@ -99,6 +118,10 @@ namespace DepotDownloader
return; return;
} }
#if STEAMKIT_UNRELEASED
proxyServer = servers.Where(x => x.UseAsProxy).FirstOrDefault();
#endif
var weightedCdnServers = servers var weightedCdnServers = servers
.Where(x => .Where(x =>
{ {

Loading…
Cancel
Save