From 05158cd768e5b386fda9ce563d4834c3de27d909 Mon Sep 17 00:00:00 2001 From: Nabil Abdel-Hafeez <7283535+987Nabil@users.noreply.github.com> Date: Sat, 12 Aug 2023 08:50:56 +0200 Subject: [PATCH] Make header value computation in request logging lazy (#2367) --- zio-http/src/main/scala/zio/http/HandlerAspect.scala | 4 ++-- zio-http/src/main/scala/zio/http/ZClientAspect.scala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/zio-http/src/main/scala/zio/http/HandlerAspect.scala b/zio-http/src/main/scala/zio/http/HandlerAspect.scala index 1be3e2f1fe..d98a8d42bd 100644 --- a/zio-http/src/main/scala/zio/http/HandlerAspect.scala +++ b/zio-http/src/main/scala/zio/http/HandlerAspect.scala @@ -705,12 +705,12 @@ private[http] trait HandlerAspects extends zio.http.internal.HeaderModifier[Hand ZIO .logLevel(level(response.status)) { - val requestHeaders = + def requestHeaders = request.headers.collect { case header: Header if loggedRequestHeaderNames.contains(header.headerName.toLowerCase) => LogAnnotation(header.headerName, header.renderedValue) }.toSet - val responseHeaders = + def responseHeaders = response.headers.collect { case header: Header if loggedResponseHeaderNames.contains(header.headerName.toLowerCase) => LogAnnotation(header.headerName, header.renderedValue) diff --git a/zio-http/src/main/scala/zio/http/ZClientAspect.scala b/zio-http/src/main/scala/zio/http/ZClientAspect.scala index c6f48a6be5..1e74251f3f 100644 --- a/zio-http/src/main/scala/zio/http/ZClientAspect.scala +++ b/zio-http/src/main/scala/zio/http/ZClientAspect.scala @@ -213,12 +213,12 @@ object ZClientAspect { case (duration, Exit.Success(response)) => ZIO .logLevel(level(response.status)) { - val requestHeaders = + def requestHeaders = headers.collect { case header: Header if loggedRequestHeaderNames.contains(header.headerName.toLowerCase) => LogAnnotation(header.headerName, header.renderedValue) }.toSet - val responseHeaders = + def responseHeaders = response.headers.collect { case header: Header if loggedResponseHeaderNames.contains(header.headerName.toLowerCase) => LogAnnotation(header.headerName, header.renderedValue)