Skip to content

Commit

Permalink
Retrieve everest_update.yaml in gzipped form to spare bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Nov 14, 2021
1 parent ee57800 commit 2e91e3c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Celeste.Mod.mm/Mod/Helpers/ModUpdaterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

namespace Celeste.Mod.Helpers {
public class ModUpdaterHelper {
private class CompressedWebClient : WebClient {
protected override WebRequest GetWebRequest(Uri address) {
// In order to compress the response, Accept-Encoding and User-Agent both have to contain "gzip":
// https://cloud.google.com/appengine/docs/standard/java/how-requests-are-handled#response_compression
HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(address);
request.AutomaticDecompression = DecompressionMethods.GZip;
request.UserAgent = "Everest/" + Everest.VersionString + "; gzip";

return request;
}
}

private class MostRecentUpdatedFirst : IComparer<ModUpdateInfo> {
public int Compare(ModUpdateInfo x, ModUpdateInfo y) {
if (x.LastUpdate != y.LastUpdate) {
Expand All @@ -29,7 +41,7 @@ public static Dictionary<string, ModUpdateInfo> DownloadModUpdateList() {

Logger.Log("ModUpdaterHelper", $"Downloading last versions list from {modUpdaterDatabaseUrl}");

using (WebClient wc = new WebClient()) {
using (WebClient wc = new CompressedWebClient()) {
string yamlData = wc.DownloadString(modUpdaterDatabaseUrl);
updateCatalog = YamlHelper.Deserializer.Deserialize<Dictionary<string, ModUpdateInfo>>(yamlData);
foreach (string name in updateCatalog.Keys) {
Expand Down

0 comments on commit 2e91e3c

Please sign in to comment.