From 618090e23d6dfb127a90058be0e3850673580702 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Thu, 5 Nov 2020 22:16:03 -0700 Subject: [PATCH] Support for proxying requests through OpenCache --- DepotDownloader/CDNClientPool.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/DepotDownloader/CDNClientPool.cs b/DepotDownloader/CDNClientPool.cs index 120bb73f..b55b3376 100644 --- a/DepotDownloader/CDNClientPool.cs +++ b/DepotDownloader/CDNClientPool.cs @@ -18,6 +18,7 @@ namespace DepotDownloader private readonly Steam3Session steamSession; private readonly uint appId; + private CDNClient.Server proxyServer; public CDNClient CDNClient { get; } @@ -29,11 +30,29 @@ namespace DepotDownloader private readonly CancellationTokenSource shutdownToken; 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) { this.steamSession = steamSession; this.appId = appId; - CDNClient = new CDNClient(steamSession.steamClient); + CDNClient = new CDNClient(steamSession.steamClient, TransformCdnClientRequest); activeConnectionPool = new ConcurrentStack(); availableServerEndpoints = new BlockingCollection(); @@ -99,6 +118,10 @@ namespace DepotDownloader return; } +#if STEAMKIT_UNRELEASED + proxyServer = servers.Where(x => x.UseAsProxy).FirstOrDefault(); +#endif + var weightedCdnServers = servers .Where(x => {