AddRequestHeader/SetRequestHostHeader is adding multiple Forwarded: <Filtered> which is giving 431-request headers field too large
Hi Folks, I am using Spring boot starter -3.4.4 and Spring cloud dependencies version 2024.0.1.
I have created two routes in application.yaml:
- route 1 is where I want to add request headers to the incoming requests which match the path predicate. For this I am using AddRequestHeaderIfNotPresent=X-Custom_header:custom_value.
- route 2 is where I want to replace the host from http://localhost:8080 to https//some-domian.com for which I am using SetRequestHostHeader.
In both the cases I am getting Http headers is larger than 16384 bytes and getting 431 http status code, where Forwarded:<Filtered> is coming multiple times in the error.
Please let me know if it is a bug in existing version or I am missing some configuration.
I have the same problem, and the console log is like this:
2025-09-24T17:15:34.523+08:00 WARN 19380 --- [gateway-service] [ctor-http-nio-8] r.n.http.server.HttpServerOperations : [3fbf3ef5, L:/172.20.100.20:8000 - R:/172.20.100.20:52861] Decoding failed: REQUEST(decodeResult: failure(io.netty.handler.codec.http.TooLongHttpHeaderException: HTTP header is larger than 8192 bytes.), version: HTTP/1.1)
GET /test1 HTTP/1.1
User-Agent:
The code is simple:
@Configuration
public class GatewayConfig {
@Bean
public RouteLocator routes(RouteLocatorBuilder routeBuilder) {
return routeBuilder
.routes()
.route("test1", spec -> spec
.order(1)
.path("/test1")
.uri("http://localhost:8000/gateway/test/user/1")
)
.build();
}
}
Visit http://localhost:8000/gateway/test/user/1" then got the correct response, but failed with the url request: http://localhost:8000/teset1".
How to solve this?