The Free Software Media System - Server Backend & API
remove tokens from log
Luke Pulverenti2b3fcaa01e01
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.csindex 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.HttpServerreturn 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;+ }+/// <summary>/// Overridable method that can be used to implement a custom hnandler/// </summary>@@ -305,10 +335,12 @@ namespace MediaBrowser.Server.Implementations.HttpServervar 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.HttpServerif (enableLog){- LoggerUtils.LogResponse(_logger, statusCode, urlString, remoteIp, duration);+ LoggerUtils.LogResponse(_logger, statusCode, urlToLog, remoteIp, duration);}}, TaskContinuationOptions.None);