5

I have created a SpringBoot application. When I am making a HTTP Post request, with a large header size, I am getting the following error :

2018-03-09 14:53:01,190 INFO  [http-nio-8080-exec-1] logging.DirectJDKLog (DirectJDKLog.java:182) - Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Request header is too large
at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:706) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.coyote.http11.Http11InputBuffer.parseHeader(Http11InputBuffer.java:853) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.coyote.http11.Http11InputBuffer.parseHeaders(Http11InputBuffer.java:565) ~[tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:703) [tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.27.jar:8.5.27]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_101]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_101]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.27.jar:8.5.27]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]

Please note that further occurrences of HTTP header parsing errors will be logged at DEBUG level (as mentioned in the Error Note). I want to fix this, so that all occurrences of such errors are logged at INFO level itself.

So, I added these two lines in application.properties file (which is located at src/main/resources/config/):

org.apache.juli.logging.UserDataHelper.CONFIG = INFO_ALL
org.apache.juli.logging.UserDataHelper.SUPPRESSION_TIME = 0
# server.maxHttpHeaderSize=10000000

But this is not working (and only the first occurrence of the error is logged at INFO level).

Please note that, setting maxHttpHeaderSize=10000000 is working fine, and it makes the large header issue to go away completely.

But what I want here is - that all such errors are logged at INFO level itself.

Any help will be appreciated :)

Additional Info : SpringBoot version : 1.5.10.RELEASE, Tomcat version : 8.5.27

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
coolcoder
  • 309
  • 1
  • 3
  • 10

1 Answers1

2

Those two properties must be set as Java system properties. There is not code-free way to set those in Spring Boot (cf. this question), so in this case I would set them in an EmbeddedServletContainerCustomizer for Spring Boot 1.x:

@Component
public class UserDataHelperCustomizer implements EmbeddedServletContainerCustomizer {

   @Override
   public void customize(ConfigurableEmbeddedServletContainer container) {
      System.setProperty("org.apache.juli.logging.UserDataHelper.CONFIG", "INFO_ALL");
   }

}

and a similar WebServerFactoryCustomizer for Spring Boot 2.x:

@Component
public class UserDataHelperCustomizer implements WebServerFactoryCustomizer<WebServerFactory> {

   @Override
   public void customize(WebServerFactory factory) {
         System.setProperty("org.apache.juli.logging.UserDataHelper.CONFIG", "INFO_ALL");
   }
}

Remark: SUPPRESSION_TIME=0 and CONFIG=INFO_ALL are equivalent, so only one needs to be set.

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43