diff --git a/ASFFreeGames/HttpClientSimple/SimpleHttpClient.cs b/ASFFreeGames/HttpClientSimple/SimpleHttpClient.cs index d040206..248c992 100644 --- a/ASFFreeGames/HttpClientSimple/SimpleHttpClient.cs +++ b/ASFFreeGames/HttpClientSimple/SimpleHttpClient.cs @@ -3,6 +3,7 @@ using System.IO; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; using System.Runtime.CompilerServices; using System.Text; using System.Threading; @@ -31,18 +32,25 @@ public SimpleHttpClient(IWebProxy? proxy = null, long timeout = 25_000) { } HttpClient = new HttpClient(HttpClientHandler, false) { Timeout = TimeSpan.FromMilliseconds(timeout) }; + HttpClient.DefaultRequestVersion = HttpVersion.Version30; + HttpClient.DefaultRequestHeaders.ExpectContinue = false; HttpClient.DefaultRequestHeaders.Add("User-Agent", "Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.12.14"); - HttpClient.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.9"); + HttpClient.DefaultRequestHeaders.Add("DNT", "1"); + HttpClient.DefaultRequestHeaders.Add("Sec-GPC", "1"); + + HttpClient.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en-US")); + HttpClient.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en", 0.8)); } public async Task GetStreamAsync(Uri uri, IEnumerable>? additionalHeaders = null, CancellationToken cancellationToken = default) { using HttpRequestMessage request = new(HttpMethod.Get, uri); + request.Version = HttpClient.DefaultRequestVersion; // Add additional headers if provided if (additionalHeaders != null) { foreach (KeyValuePair header in additionalHeaders) { - request.Headers.TryAddWithoutValidation(header.Key, header.Value); + request.Headers.Add(header.Key, header.Value); } } diff --git a/ASFFreeGames/Reddit/RedditHelper.cs b/ASFFreeGames/Reddit/RedditHelper.cs index 1bbfc3f..8875edd 100644 --- a/ASFFreeGames/Reddit/RedditHelper.cs +++ b/ASFFreeGames/Reddit/RedditHelper.cs @@ -165,7 +165,10 @@ private static async ValueTask GetPayload(SimpleHttpClient httpClient, { "Accept", "application/json" }, { "Sec-Fetch-Site", "none" }, { "Sec-Fetch-Mode", "no-cors" }, - { "Sec-Fetch-Dest", "empty" } + { "Sec-Fetch-Dest", "empty" }, + { "x-sec-fetch-dest", "empty" }, + { "x-sec-fetch-mode", "no-cors" }, + { "x-sec-fetch-site", "none" }, }; for (int t = 0; t < retry; t++) { @@ -233,7 +236,7 @@ private static async ValueTask GetPayload(SimpleHttpClient httpClient, /// /// The cancellation token. /// True if the request was handled & awaited, false otherwise. - private static async ValueTask HandleTooManyRequest(HttpStreamResponse response, int maxTimeToWait = 60, CancellationToken cancellationToken = default) { + private static async ValueTask HandleTooManyRequest(HttpStreamResponse response, int maxTimeToWait = 45, CancellationToken cancellationToken = default) { if (response.StatusCode is HttpStatusCode.Forbidden or HttpStatusCode.TooManyRequests) { if (response.Response.Headers.TryGetValues("x-ratelimit-remaining", out IEnumerable? rateLimitRemaining)) { if (int.TryParse(rateLimitRemaining.FirstOrDefault(), out int remaining) && (remaining <= 0)) { @@ -269,7 +272,6 @@ private static async ValueTask HandleTooManyRequest(HttpStreamResponse res /// The parsed JSON object, or null if parsing fails. private static async Task ParseJsonNode(HttpStreamResponse stream, CancellationToken cancellationToken) { string data = await stream.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - ArchiSteamFarm.Core.ASF.ArchiLogger.LogGenericDebug($"Response: {data}"); return JsonNode.Parse(data); }