DEV Community

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

Posted on

27

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

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

Sentry mobile image

Mobile Vitals: A first step to Faster Apps

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read the guide

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay