Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebClient max header size

Is there any way I can configure the max header size for a response?

I get the following error from the netty framework :

io.netty.handler.codec.TooLongFrameException: HTTP header is larger than 8192 bytes.
    at io.netty.handler.codec.http.HttpObjectDecoder$HeaderParser.newException(HttpObjectDecoder.java:983)
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 

Apparently reactor added an API for this, but I don't see how is this controllable in the WebClient of spring Web Flux. I am using the following version

      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
        <version>2.3.2.RELEASE</version>
      </dependency>

Any ideas?

like image 665
Dadddaism Avatar asked Sep 18 '25 14:09

Dadddaism


2 Answers

You can configure reactor's reactor.netty.http.client.HttpClient to have custom maxHeaderSize and plug this preconfigured HttpClient in your WebClient instance.

HttpClient httpClient =
    HttpClient.create().httpResponseDecoder(spec -> spec.maxHeaderSize(32 * 1024));

WebClient webClient =
    WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient))
    .build();
like image 181
Akhil Bojedla Avatar answered Sep 23 '25 11:09

Akhil Bojedla


In a Spring Boot app, the max HTTP header size is configured using:

server.max-http-header-size=65536

I have found this solved the above issue on spring cloud gateway, so worth a try.

like image 26
charlb Avatar answered Sep 23 '25 12:09

charlb