Reputation: 33
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?
Upvotes: 3
Views: 7573
Reputation: 21
I ran into the same issue, I was able to fix it with the below config.
server.max-http-request-header-size: 40000
This applies from Spring Boot 3.0, because the previous server.max-http-header-size
property has been deprecated.
Upvotes: 2
Reputation: 61
I got problem like this. I can open this link by google chrome, by terminal. It's ok, but if i use webClient, i got problem about size of headers. I use a lot of methods for resolve this problem.
As a result, I tried to use OkHttpClient, and got correct result!!!:
val client = OkHttpClient()
val request = Request.Builder()
.url("https://example.com")
.build()
client.newCall(request).execute().use { response ->
if (response.isSuccessful) {
val responseBody: ResponseBody? = response.body
val responseString = responseBody?.string()
println(responseString)
} else {
println("Error: ${response.code}")
}
}
Upvotes: 0
Reputation: 1249
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.
Upvotes: 3
Reputation: 2228
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();
Upvotes: 7