Skip to content

Commit

Permalink
Send Dalamud user-agent when downloading plugins (#1550)
Browse files Browse the repository at this point in the history
Sets the user-agent on all HappyHttp requests to `Dalamud/<Version>`, and pass `Accept: application/zip` in plugin downloads.
  • Loading branch information
anna-is-cute committed Nov 28, 2023
1 parent 473e243 commit fcebd15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Dalamud/Networking/Http/HappyHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;

using Dalamud.Utility;

namespace Dalamud.Networking.Http;

Expand All @@ -25,7 +28,16 @@ private HappyHttpClient()
{
AutomaticDecompression = DecompressionMethods.All,
ConnectCallback = this.SharedHappyEyeballsCallback.ConnectCallback,
});
})
{
DefaultRequestHeaders =
{
UserAgent =
{
new ProductInfoHeaderValue("Dalamud", Util.AssemblyVersion),
},
},
};
}

/// <summary>
Expand Down
14 changes: 13 additions & 1 deletion Dalamud/Plugin/Internal/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -1196,7 +1198,17 @@ public string GetBanReason(PluginManifest manifest)
private async Task<Stream> DownloadPluginAsync(RemotePluginManifest repoManifest, bool useTesting)
{
var downloadUrl = useTesting ? repoManifest.DownloadLinkTesting : repoManifest.DownloadLinkInstall;
var response = await this.happyHttpClient.SharedHttpClient.GetAsync(downloadUrl);
var request = new HttpRequestMessage(HttpMethod.Get, downloadUrl)
{
Headers =
{
Accept =
{
new MediaTypeWithQualityHeaderValue("application/zip"),
},
},
};
var response = await this.happyHttpClient.SharedHttpClient.SendAsync(request);
response.EnsureSuccessStatusCode();

return await response.Content.ReadAsStreamAsync();
Expand Down

0 comments on commit fcebd15

Please sign in to comment.