From bb7ab95b253916d15a50d574fbc09cd8d71327fa Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Mon, 8 Feb 2021 18:18:37 +0100 Subject: [PATCH] Avoid computing the AbsoluteUri if logging is disabled (#721) --- src/ReverseProxy/Service/Proxy/HttpProxy.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ReverseProxy/Service/Proxy/HttpProxy.cs b/src/ReverseProxy/Service/Proxy/HttpProxy.cs index efc4800d4..bcdb06be6 100644 --- a/src/ReverseProxy/Service/Proxy/HttpProxy.cs +++ b/src/ReverseProxy/Service/Proxy/HttpProxy.cs @@ -285,7 +285,7 @@ public async Task ProxyAsync( var request = context.Request; destinationRequest.RequestUri ??= RequestUtilities.MakeDestinationAddress(destinationPrefix, request.Path, request.QueryString); - Log.Proxying(_logger, destinationRequest.RequestUri.AbsoluteUri); + Log.Proxying(_logger, destinationRequest.RequestUri); // TODO: What if they replace the HttpContent object? That would mess with our tracking and error handling. return (destinationRequest, requestContent); @@ -652,9 +652,13 @@ public static void HttpDowngradeDetected(ILogger logger) _httpDowngradeDetected(logger, null); } - public static void Proxying(ILogger logger, string targetUrl) + public static void Proxying(ILogger logger, Uri targetUrl) { - _proxying(logger, targetUrl, null); + // Avoid computing the AbsoluteUri unless logging is enabled + if (logger.IsEnabled(LogLevel.Information)) + { + _proxying(logger, targetUrl.AbsoluteUri, null); + } } public static void ErrorProxying(ILogger logger, ProxyError error, Exception ex)