From 838dc96aa9ef2c3b61ae43582d4fede0f4421cfe Mon Sep 17 00:00:00 2001 From: baliasnyifeliks Date: Wed, 14 Jan 2026 08:47:38 +0200 Subject: [PATCH] refactor(uakino): replace Http.Get with custom GetString method Implement a new GetString method using HttpClient for better control over HTTP requests including proxy handling, SSL validation, and timeout management. This replaces the previous Http.Get calls throughout the UAKino module to standardize request handling and improve reliability. --- UAKino/UAKinoInvoke.cs | 51 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/UAKino/UAKinoInvoke.cs b/UAKino/UAKinoInvoke.cs index 03bd315..be6e528 100644 --- a/UAKino/UAKinoInvoke.cs +++ b/UAKino/UAKinoInvoke.cs @@ -1,8 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; using System.Text.Json; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using System.Web; using HtmlAgilityPack; @@ -62,7 +66,7 @@ namespace UAKino }; _onLog?.Invoke($"UAKino search: {searchUrl}"); - string html = await Http.Get(searchUrl, headers: headers, proxy: _proxyManager.Get()); + string html = await GetString(searchUrl, headers); if (string.IsNullOrEmpty(html)) continue; @@ -147,7 +151,7 @@ namespace UAKino try { _onLog?.Invoke($"UAKino playlist: {url}"); - string payload = await Http.Get(url, headers: headers, proxy: _proxyManager.Get()); + string payload = await GetString(url, headers); if (string.IsNullOrEmpty(payload)) return null; @@ -189,7 +193,7 @@ namespace UAKino try { _onLog?.Invoke($"UAKino movie page: {href}"); - string html = await Http.Get(href, headers: headers, proxy: _proxyManager.Get()); + string html = await GetString(href, headers); if (string.IsNullOrEmpty(html)) return null; @@ -232,7 +236,7 @@ namespace UAKino try { _onLog?.Invoke($"UAKino parse player: {url}"); - string html = await Http.Get(url, headers: headers, proxy: _proxyManager.Get()); + string html = await GetString(url, headers); if (string.IsNullOrEmpty(html)) return null; @@ -253,6 +257,45 @@ namespace UAKino } } + private async Task GetString(string url, List headers, int timeoutSeconds = 15) + { + var handler = new HttpClientHandler + { + AllowAutoRedirect = true, + AutomaticDecompression = DecompressionMethods.Brotli | DecompressionMethods.GZip | DecompressionMethods.Deflate, + SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13 + }; + + handler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; + + var proxy = _proxyManager.Get(); + if (proxy != null) + { + handler.UseProxy = true; + handler.Proxy = proxy; + } + else + { + handler.UseProxy = false; + } + + using var client = new HttpClient(handler); + using var req = new HttpRequestMessage(HttpMethod.Get, url); + + if (headers != null) + { + foreach (var h in headers) + req.Headers.TryAddWithoutValidation(h.name, h.val); + } + + using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Math.Max(5, timeoutSeconds))); + using var response = await client.SendAsync(req, cts.Token).ConfigureAwait(false); + if (!response.IsSuccessStatusCode) + return null; + + return await response.Content.ReadAsStringAsync(cts.Token).ConfigureAwait(false); + } + private List ParsePlaylistHtml(string html) { var items = new List();