From 52e4f5ea597590185c13ed596b5eb36677a20eb4 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Tue, 19 Mar 2019 14:51:42 -0400 Subject: [PATCH] Set traceRequestBody to false by default (#3439) traceRequestBody requires the body to be buffered which reduces performance and can be problematic, such as when used in combination with `zuul.use-filter=true` and `zuul.servlet-path=/` See https://github.com/spring-cloud/spring-cloud-netflix/issues/3418 traceRequestBody should only be set when logging the request body is actually necessary. --- .../cloud/netflix/zuul/filters/ZuulProperties.java | 2 +- .../zuul/filters/ProxyRequestHelperTests.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/ZuulProperties.java b/spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/ZuulProperties.java index e2439a90d..d94791dad 100755 --- a/spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/ZuulProperties.java +++ b/spring-cloud-netflix-zuul/src/main/java/org/springframework/cloud/netflix/zuul/filters/ZuulProperties.java @@ -137,7 +137,7 @@ public class ZuulProperties { /** * Flag to say that request bodies can be traced. */ - private boolean traceRequestBody = true; + private boolean traceRequestBody = false; /** * Flag to say that path elements past the first semicolon can be dropped. diff --git a/spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java b/spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java index a84b3a87b..0dacdcf8f 100644 --- a/spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java +++ b/spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java @@ -130,7 +130,9 @@ public class ProxyRequestHelperTests { RequestContext context = RequestContext.getCurrentContext(); context.setRequest(request); - ProxyRequestHelper helper = new ProxyRequestHelper(new ZuulProperties()); + ZuulProperties zuulProperties = new ZuulProperties(); + zuulProperties.setTraceRequestBody(true); + ProxyRequestHelper helper = new ProxyRequestHelper(zuulProperties); assertThat(helper.shouldDebugBody(context)).as("shouldDebugBody wrong").isTrue(); } @@ -139,7 +141,9 @@ public class ProxyRequestHelperTests { public void shouldDebugBodyNullRequest() throws Exception { RequestContext context = RequestContext.getCurrentContext(); - ProxyRequestHelper helper = new ProxyRequestHelper(new ZuulProperties()); + ZuulProperties zuulProperties = new ZuulProperties(); + zuulProperties.setTraceRequestBody(true); + ProxyRequestHelper helper = new ProxyRequestHelper(zuulProperties); assertThat(helper.shouldDebugBody(context)).as("shouldDebugBody wrong").isTrue(); } @@ -151,7 +155,9 @@ public class ProxyRequestHelperTests { RequestContext context = RequestContext.getCurrentContext(); context.setRequest(request); - ProxyRequestHelper helper = new ProxyRequestHelper(new ZuulProperties()); + ZuulProperties zuulProperties = new ZuulProperties(); + zuulProperties.setTraceRequestBody(true); + ProxyRequestHelper helper = new ProxyRequestHelper(zuulProperties); assertThat(helper.shouldDebugBody(context)).as("shouldDebugBody wrong").isTrue(); }