Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set maxHttpHeaderSize in spring-boot 3.x

As stated in the Spring Boot 3 Migration Guide the server.max-http-header-size property has been deprecated. You can use the server.max-http-request-header-size property to set the max http request header size only.

I get the following Exception:

org.apache.coyote.http11.HeadersTooLargeException: An attempt was made to write 
more data to the response headers than there was room available in the buffer. 
Increase maxHttpHeaderSize on the connector 
or write less data into the response headers.

I need to increase the max http response header size in an embedded Tomcat 10. Tomcat 10 supports both the maxHttpHeaderSize and the maxHttpResponseHeaderSize attributes.

How I can set these in spring boot 3.x with a WebServerFactoryCustomizer?

like image 407
pero_hero Avatar asked Mar 13 '26 09:03

pero_hero


2 Answers

You can create a WebServerFactoryCustomer as shown in the Spring Boot documentation.

For your use case, that would look something like this:

    @Component
    public class TomcatCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

        @Override
        public void customize(TomcatServletWebServerFactory server) {
            server.addConnectorCustomizers((connector) -> {
                ProtocolHandler handler = connector.getProtocolHandler();
                if (handler instanceof AbstractHttp11Protocol<?> protocol) {
                    protocol.setMaxHttpResponseHeaderSize(x);
                }
            });
        }

    }

Spring Boot 3.1.0 will introduce a property server.tomcat.maxHttpResponseHeaderSize to make this easier to configure.

like image 187
Scott Frederick Avatar answered Mar 15 '26 22:03

Scott Frederick


For Jetty and Tomcat the following properties exist in Spring Boot 3.3.2:

  • Tomcat: server.tomcat.max-http-response-header-size

  • Jetty: server.jetty.max-http-response-header-size

See Spring Boot Common Application Properties.

like image 42
anessi Avatar answered Mar 15 '26 22:03

anessi