From 2b3fcaa01e01a9c4574bd3c9d67bc102c1713bc0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 15 Mar 2016 15:11:53 -0400 Subject: remove tokens from log --- .../HttpServer/HttpListenerHost.cs | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index c284007f7c..93bfcbbab3 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -288,6 +288,36 @@ namespace MediaBrowser.Server.Implementations.HttpServer return Path.GetExtension(parts[0]); } + public static string RemoveQueryStringByKey(string url, string key) + { + var uri = new Uri(url); + + // this gets all the query string key value pairs as a collection + var newQueryString = MyHttpUtility.ParseQueryString(uri.Query); + + if (newQueryString.Count == 0) + { + return url; + } + + // this removes the key if exists + newQueryString.Remove(key); + + // this gets the page path from root without QueryString + string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); + + return newQueryString.Count > 0 + ? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString) + : pagePathWithoutQueryString; + } + + private string GetUrlToLog(string url) + { + url = RemoveQueryStringByKey(url, "api_key"); + + return url; + } + /// /// Overridable method that can be used to implement a custom hnandler /// @@ -305,10 +335,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer var urlString = url.OriginalString; var enableLog = EnableLogging(urlString, localPath); + var urlToLog = urlString; if (enableLog) { - LoggerUtils.LogRequest(_logger, urlString, httpReq.HttpMethod, httpReq.UserAgent); + urlToLog = GetUrlToLog(urlString); + LoggerUtils.LogRequest(_logger, urlToLog, httpReq.HttpMethod, httpReq.UserAgent); } if (string.Equals(localPath, "/mediabrowser/", StringComparison.OrdinalIgnoreCase) || @@ -390,7 +422,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (enableLog) { - LoggerUtils.LogResponse(_logger, statusCode, urlString, remoteIp, duration); + LoggerUtils.LogResponse(_logger, statusCode, urlToLog, remoteIp, duration); } }, TaskContinuationOptions.None); -- cgit v1.2.3 From e321d3c544405994b08b48421eaf80c27e10f6ab Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Mar 2016 00:14:38 -0400 Subject: add error checking --- MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index e00a68e32b..463e91fd4c 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -498,7 +498,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV private bool IsListingProviderEnabledForTuner(ListingsProviderInfo info, string tunerHostId) { - return info.EnableAllTuners || info.EnabledTuners.Contains(tunerHostId ?? string.Empty, StringComparer.OrdinalIgnoreCase); + if (info.EnableAllTuners) + { + return true; + } + + if (string.IsNullOrWhiteSpace(tunerHostId)) + { + throw new ArgumentNullException("tunerHostId"); + } + + return info.EnabledTuners.Contains(tunerHostId, StringComparer.OrdinalIgnoreCase); } private async Task> GetProgramsAsyncInternal(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) -- cgit v1.2.3