mirror of
https://github.com/Jackett/Jackett
synced 2025-03-10 06:03:09 +00:00
This reverts commit 79fa3b9e0d
.
This commit is contained in:
parent
08c41c6daa
commit
5f457fcb29
5 changed files with 143 additions and 43 deletions
|
@ -1,58 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Jackett.Common.Utils.Clients
|
||||
{
|
||||
public abstract class BaseWebResult
|
||||
{
|
||||
private Encoding _encoding;
|
||||
|
||||
public Encoding Encoding
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_encoding != null)
|
||||
return _encoding;
|
||||
if (Request.Encoding != null)
|
||||
_encoding = Request.Encoding;
|
||||
else if (Headers.ContainsKey("content-type"))
|
||||
{
|
||||
var charsetRegexMatch = Regex.Match(Headers["content-type"][0], @"charset=([\w-]+)", RegexOptions.Compiled);
|
||||
if (charsetRegexMatch.Success)
|
||||
{
|
||||
var charset = charsetRegexMatch.Groups[1].Value;
|
||||
try
|
||||
{
|
||||
_encoding = Encoding.GetEncoding(charset);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Encoding not found or not enabled on current machine.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_encoding ??= Encoding.UTF8;
|
||||
|
||||
return _encoding;
|
||||
}
|
||||
set => _encoding = value;
|
||||
}
|
||||
|
||||
public Encoding Encoding { get; set; }
|
||||
public HttpStatusCode Status { get; set; }
|
||||
public string Cookies { get; set; }
|
||||
public string RedirectingTo { get; set; }
|
||||
public WebRequest Request { get; set; }
|
||||
public Dictionary<string, string[]> Headers { get; protected set; } =
|
||||
new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||
public Dictionary<string, string[]> Headers = new Dictionary<string, string[]>();
|
||||
|
||||
public bool IsRedirect => Status == HttpStatusCode.Redirect ||
|
||||
Status == HttpStatusCode.RedirectKeepVerb ||
|
||||
Status == HttpStatusCode.RedirectMethod ||
|
||||
Status == HttpStatusCode.Found ||
|
||||
Status == HttpStatusCode.MovedPermanently;
|
||||
public bool IsRedirect => Status == System.Net.HttpStatusCode.Redirect ||
|
||||
Status == System.Net.HttpStatusCode.RedirectKeepVerb ||
|
||||
Status == System.Net.HttpStatusCode.RedirectMethod ||
|
||||
Status == System.Net.HttpStatusCode.Found ||
|
||||
Status == System.Net.HttpStatusCode.MovedPermanently;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -294,6 +294,40 @@ namespace Jackett.Common.Utils.Clients
|
|||
result.Cookies = cookieBuilder.ToString().Trim();
|
||||
}
|
||||
ServerUtil.ResureRedirectIsFullyQualified(webRequest, result);
|
||||
Encoding encoding = null;
|
||||
if (webRequest.Encoding != null)
|
||||
{
|
||||
encoding = webRequest.Encoding;
|
||||
}
|
||||
else if (result.Headers.ContainsKey("content-type"))
|
||||
{
|
||||
var CharsetRegex = new Regex(@"charset=([\w-]+)", RegexOptions.Compiled);
|
||||
var CharsetRegexMatch = CharsetRegex.Match(result.Headers["content-type"][0]);
|
||||
if (CharsetRegexMatch.Success)
|
||||
{
|
||||
var charset = CharsetRegexMatch.Groups[1].Value;
|
||||
try
|
||||
{
|
||||
encoding = Encoding.GetEncoding(charset);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Error loading encoding {2} based on header {3}: {4}", ClientType, webRequest.Url, charset, result.Headers["content-type"][0], ex));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Got header without charset: {2}", ClientType, webRequest.Url, result.Headers["content-type"][0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (encoding == null)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): No encoding detected, defaulting to UTF-8", ClientType, webRequest.Url));
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
result.Encoding = encoding;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,6 +314,40 @@ namespace Jackett.Common.Utils.Clients
|
|||
result.Cookies = cookieBuilder.ToString().Trim();
|
||||
}
|
||||
ServerUtil.ResureRedirectIsFullyQualified(webRequest, result);
|
||||
Encoding encoding = null;
|
||||
if (webRequest.Encoding != null)
|
||||
{
|
||||
encoding = webRequest.Encoding;
|
||||
}
|
||||
else if (result.Headers.ContainsKey("content-type"))
|
||||
{
|
||||
var CharsetRegex = new Regex(@"charset=([\w-]+)", RegexOptions.Compiled);
|
||||
var CharsetRegexMatch = CharsetRegex.Match(result.Headers["content-type"][0]);
|
||||
if (CharsetRegexMatch.Success)
|
||||
{
|
||||
var charset = CharsetRegexMatch.Groups[1].Value;
|
||||
try
|
||||
{
|
||||
encoding = Encoding.GetEncoding(charset);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Error loading encoding {2} based on header {3}: {4}", ClientType, webRequest.Url, charset, result.Headers["content-type"][0], ex));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Got header without charset: {2}", ClientType, webRequest.Url, result.Headers["content-type"][0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (encoding == null)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): No encoding detected, defaulting to UTF-8", ClientType, webRequest.Url));
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
result.Encoding = encoding;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -314,6 +314,40 @@ namespace Jackett.Common.Utils.Clients
|
|||
result.Cookies = cookieBuilder.ToString().Trim();
|
||||
}
|
||||
ServerUtil.ResureRedirectIsFullyQualified(webRequest, result);
|
||||
Encoding encoding = null;
|
||||
if (webRequest.Encoding != null)
|
||||
{
|
||||
encoding = webRequest.Encoding;
|
||||
}
|
||||
else if (result.Headers.ContainsKey("content-type"))
|
||||
{
|
||||
var CharsetRegex = new Regex(@"charset=([\w-]+)", RegexOptions.Compiled);
|
||||
var CharsetRegexMatch = CharsetRegex.Match(result.Headers["content-type"][0]);
|
||||
if (CharsetRegexMatch.Success)
|
||||
{
|
||||
var charset = CharsetRegexMatch.Groups[1].Value;
|
||||
try
|
||||
{
|
||||
encoding = Encoding.GetEncoding(charset);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Error loading encoding {2} based on header {3}: {4}", ClientType, webRequest.Url, charset, result.Headers["content-type"][0], ex));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Got header without charset: {2}", ClientType, webRequest.Url, result.Headers["content-type"][0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (encoding == null)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): No encoding detected, defaulting to UTF-8", ClientType, webRequest.Url));
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
result.Encoding = encoding;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -297,6 +297,40 @@ namespace Jackett.Common.Utils.Clients
|
|||
result.Cookies = cookieBuilder.ToString().Trim();
|
||||
}
|
||||
ServerUtil.ResureRedirectIsFullyQualified(webRequest, result);
|
||||
Encoding encoding = null;
|
||||
if (webRequest.Encoding != null)
|
||||
{
|
||||
encoding = webRequest.Encoding;
|
||||
}
|
||||
else if (result.Headers.ContainsKey("content-type"))
|
||||
{
|
||||
var CharsetRegex = new Regex(@"charset=([\w-]+)", RegexOptions.Compiled);
|
||||
var CharsetRegexMatch = CharsetRegex.Match(result.Headers["content-type"][0]);
|
||||
if (CharsetRegexMatch.Success)
|
||||
{
|
||||
var charset = CharsetRegexMatch.Groups[1].Value;
|
||||
try
|
||||
{
|
||||
encoding = Encoding.GetEncoding(charset);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Error loading encoding {2} based on header {3}: {4}", ClientType, webRequest.Url, charset, result.Headers["content-type"][0], ex));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): Got header without charset: {2}", ClientType, webRequest.Url, result.Headers["content-type"][0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (encoding == null)
|
||||
{
|
||||
logger.Error(string.Format("WebClient({0}).GetString(Url:{1}): No encoding detected, defaulting to UTF-8", ClientType, webRequest.Url));
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
result.Encoding = encoding;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue