Skip to content

Commit 9ed08d4

Browse files
committed
Bring back support for CDN auth tokens
Needed for some Chinese servers. It was removed in #1022. Fixes #1372.
1 parent 74f1c7b commit 9ed08d4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

SteamKit2/SteamKit2/Steam/CDN/Client.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ public void Dispose()
6363
/// This is used for decrypting filenames (if needed) in depot manifests.
6464
/// </param>
6565
/// <param name="proxyServer">Optional content server marked as UseAsProxy which transforms the request.</param>
66+
/// <param name="cdnAuthToken">CDN auth token for CDN content server endpoints if necessary. Get one with <see cref="SteamApps.GetCDNAuthToken"/>.</param>
6667
/// <returns>A <see cref="DepotManifest"/> instance that contains information about the files present within a depot.</returns>
6768
/// <exception cref="System.ArgumentNullException"><see ref="server"/> was null.</exception>
6869
/// <exception cref="HttpRequestException">An network error occurred when performing the request.</exception>
6970
/// <exception cref="SteamKitWebRequestException">A network error occurred when performing the request.</exception>
70-
public async Task<DepotManifest> DownloadManifestAsync( uint depotId, ulong manifestId, ulong manifestRequestCode, Server server, byte[]? depotKey = null, Server? proxyServer = null )
71+
public async Task<DepotManifest> DownloadManifestAsync( uint depotId, ulong manifestId, ulong manifestRequestCode, Server server, byte[]? depotKey = null, Server? proxyServer = null, string? cdnAuthToken = null )
7172
{
7273
ArgumentNullException.ThrowIfNull( server );
7374

@@ -83,7 +84,7 @@ public async Task<DepotManifest> DownloadManifestAsync( uint depotId, ulong mani
8384
url = $"depot/{depotId}/manifest/{manifestId}/{MANIFEST_VERSION}";
8485
}
8586

86-
using var request = new HttpRequestMessage( HttpMethod.Get, BuildCommand( server, url, proxyServer ) );
87+
using var request = new HttpRequestMessage( HttpMethod.Get, BuildCommand( server, url, cdnAuthToken, proxyServer ) );
8788

8889
using var cts = new CancellationTokenSource();
8990
cts.CancelAfter( RequestTimeout );
@@ -175,11 +176,12 @@ public async Task<DepotManifest> DownloadManifestAsync( uint depotId, ulong mani
175176
/// This is used to process the chunk data.
176177
/// </param>
177178
/// <param name="proxyServer">Optional content server marked as UseAsProxy which transforms the request.</param>
179+
/// <param name="cdnAuthToken">CDN auth token for CDN content server endpoints if necessary. Get one with <see cref="SteamApps.GetCDNAuthToken"/>.</param>
178180
/// <exception cref="System.ArgumentNullException">chunk's <see cref="DepotManifest.ChunkData.ChunkID"/> was null.</exception>
179181
/// <exception cref="System.IO.InvalidDataException">Thrown if the downloaded data does not match the expected length.</exception>
180182
/// <exception cref="HttpRequestException">An network error occurred when performing the request.</exception>
181183
/// <exception cref="SteamKitWebRequestException">A network error occurred when performing the request.</exception>
182-
public async Task<int> DownloadDepotChunkAsync( uint depotId, DepotManifest.ChunkData chunk, Server server, byte[] destination, byte[]? depotKey = null, Server? proxyServer = null )
184+
public async Task<int> DownloadDepotChunkAsync( uint depotId, DepotManifest.ChunkData chunk, Server server, byte[] destination, byte[]? depotKey = null, Server? proxyServer = null, string? cdnAuthToken = null )
183185
{
184186
ArgumentNullException.ThrowIfNull( server );
185187
ArgumentNullException.ThrowIfNull( chunk );
@@ -208,7 +210,7 @@ public async Task<int> DownloadDepotChunkAsync( uint depotId, DepotManifest.Chun
208210
var chunkID = Utils.EncodeHexString( chunk.ChunkID );
209211
var url = $"depot/{depotId}/chunk/{chunkID}";
210212

211-
using var request = new HttpRequestMessage( HttpMethod.Get, BuildCommand( server, url, proxyServer ) );
213+
using var request = new HttpRequestMessage( HttpMethod.Get, BuildCommand( server, url, cdnAuthToken, proxyServer ) );
212214

213215
using var cts = new CancellationTokenSource();
214216
cts.CancelAfter( RequestTimeout );
@@ -285,14 +287,15 @@ public async Task<int> DownloadDepotChunkAsync( uint depotId, DepotManifest.Chun
285287
}
286288
}
287289

288-
static Uri BuildCommand( Server server, string command, Server? proxyServer )
290+
static Uri BuildCommand( Server server, string command, string? query, Server? proxyServer )
289291
{
290292
var uriBuilder = new UriBuilder
291293
{
292294
Scheme = server.Protocol == Server.ConnectionProtocol.HTTP ? "http" : "https",
293295
Host = server.VHost,
294296
Port = server.Port,
295297
Path = command,
298+
Query = query ?? string.Empty,
296299
};
297300

298301
if ( proxyServer != null && proxyServer.UseAsProxy && proxyServer.ProxyRequestPathTemplate != null )

0 commit comments

Comments
 (0)