Send Dalamud user-agent when downloading plugins (#1550)

Sets the user-agent on all HappyHttp requests to `Dalamud/<Version>`, and pass `Accept: application/zip` in plugin downloads.
This commit is contained in:
Anna 2023-11-28 17:04:36 +00:00 committed by GitHub
parent 473e24301d
commit fcebd15077
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -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;
@ -25,7 +28,16 @@ internal class HappyHttpClient : IDisposable, IServiceType
{
AutomaticDecompression = DecompressionMethods.All,
ConnectCallback = this.SharedHappyEyeballsCallback.ConnectCallback,
});
})
{
DefaultRequestHeaders =
{
UserAgent =
{
new ProductInfoHeaderValue("Dalamud", Util.AssemblyVersion),
},
},
};
}
/// <summary>

View file

@ -5,6 +5,8 @@ using System.Diagnostics;
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;
@ -1196,7 +1198,17 @@ internal partial class PluginManager : IDisposable, IServiceType
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();