From cc0406653a6f96f7d3955d94730bb5507daeb0c6 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 6 Apr 2016 22:53:14 +0200 Subject: [PATCH] Readded logging Download Client responses. --- src/NzbDrone.Common/Http/HttpClient.cs | 5 +++++ src/NzbDrone.Common/Http/HttpRequest.cs | 1 + src/NzbDrone.Common/Http/HttpRequestBuilder.cs | 2 ++ .../Download/Clients/Deluge/DelugeProxy.cs | 12 +++++++----- .../Download/Clients/NzbVortex/NzbVortexProxy.cs | 5 ++++- .../Download/Clients/Nzbget/NzbgetProxy.cs | 7 ++++--- .../Download/Clients/Sabnzbd/SabnzbdProxy.cs | 2 ++ .../Clients/Transmission/TransmissionProxy.cs | 1 + .../Download/Clients/qBittorrent/QBittorrentProxy.cs | 1 + .../Download/Clients/uTorrent/UTorrentProxy.cs | 1 + 10 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Common/Http/HttpClient.cs b/src/NzbDrone.Common/Http/HttpClient.cs index 03ab0c46f..baf78a2f3 100644 --- a/src/NzbDrone.Common/Http/HttpClient.cs +++ b/src/NzbDrone.Common/Http/HttpClient.cs @@ -81,6 +81,11 @@ public HttpResponse Execute(HttpRequest request) response = interceptor.PostResponse(response); } + if (request.LogResponseContent) + { + _logger.Trace("Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content); + } + if (!RuntimeInfoBase.IsProduction && (response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.MovedPermanently || diff --git a/src/NzbDrone.Common/Http/HttpRequest.cs b/src/NzbDrone.Common/Http/HttpRequest.cs index 0a7bf0b51..bf2fe3568 100644 --- a/src/NzbDrone.Common/Http/HttpRequest.cs +++ b/src/NzbDrone.Common/Http/HttpRequest.cs @@ -36,6 +36,7 @@ public HttpRequest(string url, HttpAccept httpAccept = null) public bool SuppressHttpError { get; set; } public bool AllowAutoRedirect { get; set; } public bool ConnectionKeepAlive { get; set; } + public bool LogResponseContent { get; set; } public Dictionary Cookies { get; private set; } public bool StoreResponseCookie { get; set; } public TimeSpan RequestTimeout { get; set; } diff --git a/src/NzbDrone.Common/Http/HttpRequestBuilder.cs b/src/NzbDrone.Common/Http/HttpRequestBuilder.cs index 38cb24d7e..c3ed3d296 100644 --- a/src/NzbDrone.Common/Http/HttpRequestBuilder.cs +++ b/src/NzbDrone.Common/Http/HttpRequestBuilder.cs @@ -21,6 +21,7 @@ public class HttpRequestBuilder public bool SuppressHttpError { get; set; } public bool AllowAutoRedirect { get; set; } public bool ConnectionKeepAlive { get; set; } + public bool LogResponseContent { get; set; } public NetworkCredential NetworkCredential { get; set; } public Dictionary Cookies { get; private set; } public List FormData { get; private set; } @@ -100,6 +101,7 @@ protected virtual void Apply(HttpRequest request) request.SuppressHttpError = SuppressHttpError; request.AllowAutoRedirect = AllowAutoRedirect; request.ConnectionKeepAlive = ConnectionKeepAlive; + request.LogResponseContent = LogResponseContent; if (NetworkCredential != null) { diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs index 82088c858..6239b4aa6 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs @@ -163,14 +163,15 @@ private JsonRpcRequestBuilder BuildRequest(DelugeSettings settings) { string url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase); - var builder = new JsonRpcRequestBuilder(url); + var requestBuilder = new JsonRpcRequestBuilder(url); + requestBuilder.LogResponseContent = true; - builder.Resource("json"); - builder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); + requestBuilder.Resource("json"); + requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); - AuthenticateClient(builder, settings); + AuthenticateClient(requestBuilder, settings); - return builder; + return requestBuilder; } protected TResult ProcessRequest(DelugeSettings settings, string method, params object[] arguments) @@ -255,6 +256,7 @@ private void AuthenticateClient(JsonRpcRequestBuilder requestBuilder, DelugeSett _authCookieCache.Remove(authKey); var authLoginRequest = requestBuilder.Call("auth.login", settings.Password).Build(); + authLoginRequest.ContentSummary = "auth.login(\"(removed)\")"; var response = _httpClient.Execute(authLoginRequest); var result = Json.Deserialize>(response.Content); if (!result.Result) diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs index f599032c1..15450c280 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs @@ -116,7 +116,10 @@ public List GetFiles(int id, NzbVortexSettings settings) private HttpRequestBuilder BuildRequest(NzbVortexSettings settings) { - return new HttpRequestBuilder(true, settings.Host, settings.Port, "api"); + var requestBuilder = new HttpRequestBuilder(true, settings.Host, settings.Port, "api"); + requestBuilder.LogResponseContent = true; + + return requestBuilder; } private T ProcessRequest(HttpRequestBuilder requestBuilder, bool requiresAuthentication, NzbVortexSettings settings) diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs index b333a890b..4dea6dd0a 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs @@ -155,10 +155,11 @@ private T ProcessRequest(NzbgetSettings settings, string method, params objec { var baseUrl = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "jsonrpc"); - var builder = new JsonRpcRequestBuilder(baseUrl, method, parameters); - builder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); + var requestBuilder = new JsonRpcRequestBuilder(baseUrl, method, parameters); + requestBuilder.LogResponseContent = true; + requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); - var httpRequest = builder.Build(); + var httpRequest = requestBuilder.Build(); HttpResponse response; try diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs index 499129d13..cc2d7eb59 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs @@ -138,6 +138,8 @@ private HttpRequestBuilder BuildRequest(string mode, SabnzbdSettings settings) .Accept(HttpAccept.Json) .AddQueryParam("mode", mode); + requestBuilder.LogResponseContent = true; + if (settings.ApiKey.IsNotNullOrWhiteSpace()) { requestBuilder.AddSuffixQueryParam("apikey", settings.ApiKey); diff --git a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionProxy.cs b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionProxy.cs index dc7a66f40..777c846fb 100644 --- a/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Transmission/TransmissionProxy.cs @@ -180,6 +180,7 @@ private HttpRequestBuilder BuildRequest(TransmissionSettings settings) .Resource("rpc") .Accept(HttpAccept.Json); + requestBuilder.LogResponseContent = true; requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); requestBuilder.AllowAutoRedirect = false; diff --git a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs index 2b92d4913..ba4670ce0 100644 --- a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs @@ -129,6 +129,7 @@ public void MoveTorrentToTopInQueue(string hash, QBittorrentSettings settings) private HttpRequestBuilder BuildRequest(QBittorrentSettings settings) { var requestBuilder = new HttpRequestBuilder(settings.UseSsl, settings.Host, settings.Port); + requestBuilder.LogResponseContent = true; requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); return requestBuilder; diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs index d23a9059d..ffb90bdec 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs @@ -162,6 +162,7 @@ private HttpRequestBuilder BuildRequest(UTorrentSettings settings) .SetHeader("Cache-Control", "no-cache") .Accept(HttpAccept.Json); + requestBuilder.LogResponseContent = true; requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); return requestBuilder;