DEV Community

Cover image for How to solve error parsing HTTP request header in Spring Boot
Mateus Malaquias
Mateus Malaquias

Posted on

How to solve error parsing HTTP request header in Spring Boot

TL;DR

Just add a line like below in your application.properties file:

server.max-http-header-size=64kb
Enter fullscreen mode Exit fullscreen mode

This sets the limit header size to 64 kilobytes.


What are HTTP headers?

According to Mozilla an HTTP header is a field of an HTTP request or response that passes additional context and metadata about the request or response. For example, a request message can use headers to indicate its preferred media formats, while a response can use header to indicate the media format of the returned body.

Why Spring Boot limit the header size?

Well, large headers will consume more memory, they can slow down the request or worst crash our server. Limit them is a safety approach.

Under the hood Spring Boot is not a server, indeed Spring can embedded 3 distinct servers, Tomcat, Jetty or Undertow. However, the configuration for them will be the same.

The default header size are:

  • Tomcat = 8kb
  • Jetty = 8kb
  • Undertow = 1mb

To change the max size, follow the TL;DR example.

Be careful when increasing the size limit always analise your situation and try to understand why the header is too large (usually are auth token).

References

Top comments (3)

Collapse
 
dagnelies profile image
Arnaud Dagnelies

What's in your headers to be so large?! 😯

Collapse
 
malaquiasdev profile image
Mateus Malaquias

Auth token, request trace id and others security things

Collapse
 
vishal_s_bc3e421a1b3e6c79 profile image
Vishal S

It is the problem with browser,Which is automatically sending you request with https instead of http.Try in different browsers.It will work for sure