This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Cloud Gateway 4.1.6!

RequestHeaderSize Filter

The RequestHeaderSize filter takes maxSize and errorHeaderName parameters. The maxSize parameter is the maximum data size allowed by the request header (including key and value). The errorHeaderName parameter sets the name of the response header containing an error message, by default it is "errorMessage". The following listing configures a RequestHeaderSize filter:

application.yml
spring:
  cloud:
    gateway:
      mvc:
        routes:
        - id: requestheadersize_route
          uri: https://example.org
          filters:
          - RequestHeaderSize=1000B
GatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.requestHeaderSize;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;

@Configuration
class RouteConfiguration {

    @Bean
    public RouterFunction<ServerResponse> gatewayRouterFunctionsRequestHeaderSize() {
		return route("requestheadersize_route")
				.GET("/**", http("https://example.org"))
					.before(requestHeaderSize("1000B"))
					.build();
    }
}

This will send a status 431 if size of any request header is greater than 1000 Bytes.