How to solve error parsing HTTP request header in Spring Boot
Mateus Malaquias
Posted on February 13, 2024
TL;DR
Just add a line like below in your application.properties file:
server.max-http-header-size=64kb
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
Posted on February 13, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.