Skip to content

Commit

Permalink
core: refactor http webclient part 17 #8529 (#9589)
Browse files Browse the repository at this point in the history
Print HTML in debug mode. Fix bugs in old implementation too
  • Loading branch information
ngosang committed Sep 22, 2020
1 parent 17a32a0 commit 24bffe9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Jackett.Common/Utils/Clients/WebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,31 @@ protected virtual void PrepareRequest(WebRequest request)

public virtual async Task<WebResult> GetResultAsync(WebRequest request)
{
logger.Debug(string.Format("WebClient({0}).GetResultAsync(Url:{1})", ClientType, request.Url));
logger.Debug($"WebClient({ClientType}).GetResultAsync(Method: {request.Type} Url: {request.Url})");
PrepareRequest(request);
await DelayRequest(request);
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.ContentBytes == null ? "<NULL>" : result.ContentBytes.Length.ToString())));

if (logger.IsDebugEnabled) // optimization to compute result.ContentString in debug mode only
{
var body = "";
var bodySize = 0;
if (result.ContentBytes != null && result.ContentBytes.Length > 0)
{
bodySize = result.ContentBytes.Length;
var contentString = result.ContentString.Trim();
if (contentString.StartsWith("<") || contentString.StartsWith("{"))
body = "\n" + contentString;
else
body = " <BINARY>";
}
logger.Debug($@"WebClient({ClientType}): Returning {result.Status} => {
(result.IsRedirect ? result.RedirectingTo + " " : "")
}{bodySize} bytes{body}");
}

if (result.Headers.TryGetValue("server", out var server) && server[0] == "cloudflare-nginx")
result.ContentString = BrowserUtil.DecodeCloudFlareProtectedEmailFromHTML(result.ContentString);
return result;
Expand Down

0 comments on commit 24bffe9

Please sign in to comment.