RequestHeaderSize Filter

RequestHeaderSize 过滤器使用 maxSizeerrorHeaderName 参数。maxSize 参数是请求标头(包括键和值)允许的最大数据大小。errorHeaderName 参数设置包含错误消息的响应标头的名称,默认值为 “errorMessage”。以下列表配置了一个 RequestHeaderSize 过滤器:

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();
    }
}

如果任何请求头的长度超过 1000 字节,这将发送状态 431。

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