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

Change byte result name to ContentBytes in preparation for merge
This commit is contained in:
Cory 2020-03-14 18:58:50 -05:00 committed by ngosang
parent 823ed8522c
commit c605c9a7ae
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());
}
else if (response.Status != HttpStatusCode.OK)
throw new Exception($"Unknown error in download: {response.Content}");
return response.Content;
throw new Exception($"Unknown error in download: {response.ContentBytes}");
return response.ContentBytes;
}
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.");
var response = await RequestBytesWithCookies(SiteLink + downloadLink);
return response.Content;
return response.ContentBytes;
}
}
}

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)
{
logger.Error("Failed download cookies: " + CookieHeader);
if (response.Content != null)
logger.Error("Failed download response:\n" + Encoding.UTF8.GetString(response.Content));
if (response.ContentBytes != null)
logger.Error("Failed download response:\n" + Encoding.UTF8.GetString(response.ContentBytes));
throw new Exception($"Remote server returned {response.Status.ToString()}" + (response.IsRedirect ? " => " + response.RedirectingTo : ""));
}
return response.Content;
return response.ContentBytes;
}
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 CaptchaText = new StringItem { Name = "Captcha Text" };
CaptchaImage.Value = captchaImageData.Content;
CaptchaImage.Value = captchaImageData.ContentBytes;
configData.AddDynamic("CaptchaImage", CaptchaImage);
configData.AddDynamic("CaptchaText", CaptchaText);

View File

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

View File

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

View File

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

View File

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

View File

@ -136,7 +136,7 @@ namespace Jackett.Common.Indexers
{
var captchaUrl = SiteLink + qCaptchaImg.GetAttribute("src");
var captchaImage = await RequestBytesWithCookies(captchaUrl, loginPage.Cookies);
configData.CaptchaImage.Value = captchaImage.Content;
configData.CaptchaImage.Value = captchaImage.ContentBytes;
}
else
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 captchaText = new StringItem { Name = "Captcha Text" };
var captchaImage = new ImageItem {Name = "Captcha Image", Value = captchaImageResponse.Content};
var captchaImage = new ImageItem {Name = "Captcha Image", Value = captchaImageResponse.ContentBytes};
configData.AddDynamic("CaptchaText", captchaText);
configData.AddDynamic("CaptchaImage", captchaImage);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -102,7 +102,7 @@ namespace Jackett.Common.Utils.Clients
var result = await Run(request);
lastRequest = DateTime.Now;
result.Request = request;
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())));
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())));
return result;
}
@ -117,8 +117,8 @@ namespace Jackett.Common.Utils.Clients
var stringResult = Mapper.Map<WebClientStringResult>(result);
string decodedContent = null;
if (result.Content != null)
decodedContent = result.Encoding.GetString(result.Content);
if (result.ContentBytes != null)
decodedContent = result.Encoding.GetString(result.ContentBytes);
stringResult.ContentString = 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) =>
{
var encoding = be.Request.Encoding ?? Encoding.UTF8;
str.ContentString = encoding.GetString(be.Content);
str.ContentString = encoding.GetString(be.ContentBytes);
});
cfg.CreateMap<WebClientStringResult, WebClientByteResult>().ForMember(x => x.Content, opt => opt.Ignore()).AfterMap((str, be) =>
cfg.CreateMap<WebClientStringResult, WebClientByteResult>().ForMember(x => x.ContentBytes, opt => opt.Ignore()).AfterMap((str, be) =>
{
if (!string.IsNullOrEmpty(str.ContentString))
{
var encoding = str.Request.Encoding ?? Encoding.UTF8;
be.Content = encoding.GetBytes(str.ContentString);
be.ContentBytes = encoding.GetBytes(str.ContentString);
}
});