mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-08-18 15:33:33 +08:00
feat.依旧修更新系统的一天
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
|
namespace LanMountainDesktop.Services.Plonds;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shared HTTP client for PLONDS manifest and package downloads.
|
||||||
|
/// CDN buckets (e.g. rains3) commonly reject anonymous clients without a User-Agent.
|
||||||
|
/// </summary>
|
||||||
|
internal static class PlondsHttpClientFactory
|
||||||
|
{
|
||||||
|
public static HttpClient Create(TimeSpan? timeout = null)
|
||||||
|
{
|
||||||
|
var handler = new SocketsHttpHandler
|
||||||
|
{
|
||||||
|
AutomaticDecompression = DecompressionMethods.All,
|
||||||
|
AllowAutoRedirect = true,
|
||||||
|
PooledConnectionLifetime = TimeSpan.FromMinutes(5)
|
||||||
|
};
|
||||||
|
|
||||||
|
var client = new HttpClient(handler)
|
||||||
|
{
|
||||||
|
Timeout = timeout ?? TimeSpan.FromMinutes(10)
|
||||||
|
};
|
||||||
|
|
||||||
|
client.DefaultRequestHeaders.UserAgent.Clear();
|
||||||
|
client.DefaultRequestHeaders.UserAgent.Add(
|
||||||
|
new ProductInfoHeaderValue("LanMountainDesktop", GetProductVersion()));
|
||||||
|
client.DefaultRequestHeaders.UserAgent.Add(
|
||||||
|
new ProductInfoHeaderValue("(+https://github.com/wwiinnddyy/LanMountainDesktop)"));
|
||||||
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
|
||||||
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetProductVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var version = Shared.Contracts.Launcher.AppVersionProvider.ResolveForCurrentProcess().Version;
|
||||||
|
return string.IsNullOrWhiteSpace(version) ? "1.0" : version.Trim();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return "1.0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user