Revert "core: refactor http webclient part 4 #8529 (#7653)"

This reverts commit c605c9a7ae.
This commit is contained in:
ngosang
2020-09-21 08:04:11 +02:00
parent 263b5b5433
commit ede3f77e6a
18 changed files with 26 additions and 26 deletions

View File

@@ -174,8 +174,8 @@ namespace Jackett.Common.Indexers.Abstract
response = await RequestBytesWithCookies(link.ToString(), headers: GetSearchHeaders()); response = await RequestBytesWithCookies(link.ToString(), headers: GetSearchHeaders());
} }
else if (response.Status != HttpStatusCode.OK) else if (response.Status != HttpStatusCode.OK)
throw new Exception($"Unknown error in download: {response.ContentBytes}"); throw new Exception($"Unknown error in download: {response.Content}");
return response.ContentBytes; return response.Content;
} }
private Dictionary<string, string> GetSearchHeaders() => new Dictionary<string, string> private Dictionary<string, string> GetSearchHeaders() => new Dictionary<string, string>

View File

@@ -255,7 +255,7 @@ namespace Jackett.Common.Indexers
throw new Exception("Unable to find download link."); throw new Exception("Unable to find download link.");
var response = await RequestBytesWithCookies(SiteLink + downloadLink); var response = await RequestBytesWithCookies(SiteLink + downloadLink);
return response.ContentBytes; return response.Content;
} }
} }
} }

View File

@@ -404,12 +404,12 @@ namespace Jackett.Common.Indexers
if (response.Status != System.Net.HttpStatusCode.OK && response.Status != System.Net.HttpStatusCode.Continue && response.Status != System.Net.HttpStatusCode.PartialContent) if (response.Status != System.Net.HttpStatusCode.OK && response.Status != System.Net.HttpStatusCode.Continue && response.Status != System.Net.HttpStatusCode.PartialContent)
{ {
logger.Error("Failed download cookies: " + CookieHeader); logger.Error("Failed download cookies: " + CookieHeader);
if (response.ContentBytes != null) if (response.Content != null)
logger.Error("Failed download response:\n" + Encoding.UTF8.GetString(response.ContentBytes)); logger.Error("Failed download response:\n" + Encoding.UTF8.GetString(response.Content));
throw new Exception($"Remote server returned {response.Status.ToString()}" + (response.IsRedirect ? " => " + response.RedirectingTo : "")); throw new Exception($"Remote server returned {response.Status.ToString()}" + (response.IsRedirect ? " => " + response.RedirectingTo : ""));
} }
return response.ContentBytes; return response.Content;
} }
protected async Task<WebClientByteResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null) protected async Task<WebClientByteResult> RequestBytesWithCookiesAndRetry(string url, string cookieOverride = null, RequestType method = RequestType.GET, string referer = null, IEnumerable<KeyValuePair<string, string>> data = null)

View File

@@ -933,7 +933,7 @@ namespace Jackett.Common.Indexers
var CaptchaImage = new ImageItem { Name = "Captcha Image" }; var CaptchaImage = new ImageItem { Name = "Captcha Image" };
var CaptchaText = new StringItem { Name = "Captcha Text" }; var CaptchaText = new StringItem { Name = "Captcha Text" };
CaptchaImage.Value = captchaImageData.ContentBytes; CaptchaImage.Value = captchaImageData.Content;
configData.AddDynamic("CaptchaImage", CaptchaImage); configData.AddDynamic("CaptchaImage", CaptchaImage);
configData.AddDynamic("CaptchaText", CaptchaText); configData.AddDynamic("CaptchaText", CaptchaText);

View File

@@ -121,7 +121,7 @@ namespace Jackett.Common.Indexers
{ {
var captchaUrl = SiteLink + qCaptchaImg.GetAttribute("src"); var captchaUrl = SiteLink + qCaptchaImg.GetAttribute("src");
var captchaImage = await RequestBytesWithCookies(captchaUrl, loginPage.Cookies); var captchaImage = await RequestBytesWithCookies(captchaUrl, loginPage.Cookies);
configData.CaptchaImage.Value = captchaImage.ContentBytes; configData.CaptchaImage.Value = captchaImage.Content;
} }
else else
{ {

View File

@@ -70,7 +70,7 @@ namespace Jackett.Common.Indexers
input_captcha = catchaInput.GetAttribute("name"); input_captcha = catchaInput.GetAttribute("name");
var captchaImage = await RequestBytesWithCookies(SiteLink + catchaImg.GetAttribute("src"), loginPage.Cookies, RequestType.GET, LoginUrl); var captchaImage = await RequestBytesWithCookies(SiteLink + catchaImg.GetAttribute("src"), loginPage.Cookies, RequestType.GET, LoginUrl);
configData.CaptchaImage.Value = captchaImage.ContentBytes; configData.CaptchaImage.Value = captchaImage.Content;
} }
else else
{ {

View File

@@ -190,7 +190,7 @@ namespace Jackett.Common.Indexers
if (captchaimg != null) if (captchaimg != null)
{ {
var captchaImage = await RequestBytesWithCookies("https:" + captchaimg.GetAttribute("src")); var captchaImage = await RequestBytesWithCookies("https:" + captchaimg.GetAttribute("src"));
configData.CaptchaImage.Value = captchaImage.ContentBytes; configData.CaptchaImage.Value = captchaImage.Content;
var codefield = LoginResultDocument.QuerySelector("input[name^=\"cap_code_\"]"); var codefield = LoginResultDocument.QuerySelector("input[name^=\"cap_code_\"]");
cap_code_field = codefield.GetAttribute("name"); cap_code_field = codefield.GetAttribute("name");

View File

@@ -1517,7 +1517,7 @@ namespace Jackett.Common.Indexers
if (captchaimg != null) if (captchaimg != null)
{ {
var captchaImage = await RequestBytesWithCookies(captchaimg.GetAttribute("src")); var captchaImage = await RequestBytesWithCookies(captchaimg.GetAttribute("src"));
configData.CaptchaImage.Value = captchaImage.ContentBytes; configData.CaptchaImage.Value = captchaImage.Content;
var codefield = doc.QuerySelector("input[name^=\"cap_code_\"]"); var codefield = doc.QuerySelector("input[name^=\"cap_code_\"]");
_capCodeField = codefield.GetAttribute("name"); _capCodeField = codefield.GetAttribute("name");

View File

@@ -136,7 +136,7 @@ namespace Jackett.Common.Indexers
{ {
var captchaUrl = SiteLink + qCaptchaImg.GetAttribute("src"); var captchaUrl = SiteLink + qCaptchaImg.GetAttribute("src");
var captchaImage = await RequestBytesWithCookies(captchaUrl, loginPage.Cookies); var captchaImage = await RequestBytesWithCookies(captchaUrl, loginPage.Cookies);
configData.CaptchaImage.Value = captchaImage.ContentBytes; configData.CaptchaImage.Value = captchaImage.Content;
} }
else else
configData.CaptchaImage.Value = Array.Empty<byte>(); configData.CaptchaImage.Value = Array.Empty<byte>();

View File

@@ -142,7 +142,7 @@ namespace Jackett.Common.Indexers
var captchaImageResponse = await RequestBytesWithCookies(captchaUrl, loginPage.Cookies, RequestType.GET, LandingUrl); var captchaImageResponse = await RequestBytesWithCookies(captchaUrl, loginPage.Cookies, RequestType.GET, LandingUrl);
var captchaText = new StringItem { Name = "Captcha Text" }; var captchaText = new StringItem { Name = "Captcha Text" };
var captchaImage = new ImageItem {Name = "Captcha Image", Value = captchaImageResponse.ContentBytes}; var captchaImage = new ImageItem {Name = "Captcha Image", Value = captchaImageResponse.Content};
configData.AddDynamic("CaptchaText", captchaText); configData.AddDynamic("CaptchaText", captchaText);
configData.AddDynamic("CaptchaImage", captchaImage); configData.AddDynamic("CaptchaImage", captchaImage);

View File

@@ -277,14 +277,14 @@ namespace Jackett.Common.Services
if (isWindows) if (isWindows)
{ {
var zipPath = Path.Combine(tempDir, "Update.zip"); var zipPath = Path.Combine(tempDir, "Update.zip");
File.WriteAllBytes(zipPath, data.ContentBytes); File.WriteAllBytes(zipPath, data.Content);
var fastZip = new FastZip(); var fastZip = new FastZip();
fastZip.ExtractZip(zipPath, tempDir, null); fastZip.ExtractZip(zipPath, tempDir, null);
} }
else else
{ {
var gzPath = Path.Combine(tempDir, "Update.tar.gz"); var gzPath = Path.Combine(tempDir, "Update.tar.gz");
File.WriteAllBytes(gzPath, data.ContentBytes); File.WriteAllBytes(gzPath, data.Content);
Stream inStream = File.OpenRead(gzPath); Stream inStream = File.OpenRead(gzPath);
Stream gzipStream = new GZipInputStream(inStream); Stream gzipStream = new GZipInputStream(inStream);

View File

@@ -216,7 +216,7 @@ namespace Jackett.Common.Utils.Clients
{ {
var result = new WebClientByteResult var result = new WebClientByteResult
{ {
ContentBytes = await response.Content.ReadAsByteArrayAsync() Content = await response.Content.ReadAsByteArrayAsync()
}; };
foreach (var header in response.Headers) foreach (var header in response.Headers)

View File

@@ -235,7 +235,7 @@ namespace Jackett.Common.Utils.Clients
var result = new WebClientByteResult var result = new WebClientByteResult
{ {
ContentBytes = await response.Content.ReadAsByteArrayAsync() Content = await response.Content.ReadAsByteArrayAsync()
}; };
foreach (var header in response.Headers) foreach (var header in response.Headers)

View File

@@ -231,7 +231,7 @@ namespace Jackett.Common.Utils.Clients
var result = new WebClientByteResult var result = new WebClientByteResult
{ {
ContentBytes = await response.Content.ReadAsByteArrayAsync() Content = await response.Content.ReadAsByteArrayAsync()
}; };
foreach (var header in response.Headers) foreach (var header in response.Headers)

View File

@@ -215,7 +215,7 @@ namespace Jackett.Common.Utils.Clients
{ {
var result = new WebClientByteResult var result = new WebClientByteResult
{ {
ContentBytes = await response.Content.ReadAsByteArrayAsync() Content = await response.Content.ReadAsByteArrayAsync()
}; };
foreach (var header in response.Headers) foreach (var header in response.Headers)

View File

@@ -2,6 +2,6 @@ namespace Jackett.Common.Utils.Clients
{ {
public class WebClientByteResult : BaseWebResult public class WebClientByteResult : BaseWebResult
{ {
public byte[] ContentBytes { get; set; } public byte[] Content { get; set; }
} }
} }

View File

@@ -102,7 +102,7 @@ namespace Jackett.Common.Utils.Clients
var result = await Run(request); var result = await Run(request);
lastRequest = DateTime.Now; lastRequest = DateTime.Now;
result.Request = request; result.Request = request;
logger.Debug(string.Format("WebClient({0}): Returning {1} => {2} bytes", ClientType, result.Status, (result.IsRedirect ? result.RedirectingTo + " " : "") + (result.ContentBytes == null ? "<NULL>" : result.ContentBytes.Length.ToString()))); logger.Debug(string.Format("WebClient({0}): Returning {1} => {2} bytes", ClientType, result.Status, (result.IsRedirect ? result.RedirectingTo + " " : "") + (result.Content == null ? "<NULL>" : result.Content.Length.ToString())));
return result; return result;
} }
@@ -117,8 +117,8 @@ namespace Jackett.Common.Utils.Clients
var stringResult = Mapper.Map<WebClientStringResult>(result); var stringResult = Mapper.Map<WebClientStringResult>(result);
string decodedContent = null; string decodedContent = null;
if (result.ContentBytes != null) if (result.Content != null)
decodedContent = result.Encoding.GetString(result.ContentBytes); decodedContent = result.Encoding.GetString(result.Content);
stringResult.ContentString = decodedContent; stringResult.ContentString = decodedContent;
logger.Debug(string.Format("WebClient({0}): Returning {1} => {2}", ClientType, result.Status, (result.IsRedirect ? result.RedirectingTo + " " : "") + (decodedContent == null ? "<NULL>" : decodedContent))); logger.Debug(string.Format("WebClient({0}): Returning {1} => {2}", ClientType, result.Status, (result.IsRedirect ? result.RedirectingTo + " " : "") + (decodedContent == null ? "<NULL>" : decodedContent)));

View File

@@ -76,15 +76,15 @@ namespace Jackett.Server
cfg.CreateMap<WebClientByteResult, WebClientStringResult>().ForMember(x => x.ContentString, opt => opt.Ignore()).AfterMap((be, str) => cfg.CreateMap<WebClientByteResult, WebClientStringResult>().ForMember(x => x.ContentString, opt => opt.Ignore()).AfterMap((be, str) =>
{ {
var encoding = be.Request.Encoding ?? Encoding.UTF8; var encoding = be.Request.Encoding ?? Encoding.UTF8;
str.ContentString = encoding.GetString(be.ContentBytes); str.ContentString = encoding.GetString(be.Content);
}); });
cfg.CreateMap<WebClientStringResult, WebClientByteResult>().ForMember(x => x.ContentBytes, opt => opt.Ignore()).AfterMap((str, be) => cfg.CreateMap<WebClientStringResult, WebClientByteResult>().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((str, be) =>
{ {
if (!string.IsNullOrEmpty(str.ContentString)) if (!string.IsNullOrEmpty(str.ContentString))
{ {
var encoding = str.Request.Encoding ?? Encoding.UTF8; var encoding = str.Request.Encoding ?? Encoding.UTF8;
be.ContentBytes = encoding.GetBytes(str.ContentString); be.Content = encoding.GetBytes(str.ContentString);
} }
}); });