aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs36
1 files changed, 34 insertions, 2 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs
index c284007f7..93bfcbbab 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;
+ }
+
/// <summary>
/// Overridable method that can be used to implement a custom hnandler
/// </summary>
@@ -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);