跳到主要内容
版本:5.0.1

DedupeResponseHeader 过滤器

DeepSeek V3 中英对照 DedupeResponseHeader Filter DedupeResponseHeader Filter

DedupeResponseHeader GatewayFilter 工厂接收一个 name 参数和一个可选的 strategy 参数。name 可以包含一个以空格分隔的响应头名称列表。以下示例配置了一个 DedupeResponseHeader 过滤器:

spring:
cloud:
gateway:
server:
webmvc:
routes:
- id: dedupe_response_header_route
uri: https://example.org
predicates:
- Path=/hello
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.dedupeResponseHeader;
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
import static org.springframework.web.servlet.function.RequestPredicates.path;

@Configuration
class RouteConfiguration {

@Bean
public RouterFunction<ServerResponse> gatewayRouterFunctionsDedupeResponseHeader() {
return route("dedupe_response_header_route")
.route(path("/hello"), http())
.before(uri("https://example.org"))
.after(dedupeResponseHeader("Access-Control-Allow-Credentials Access-Control-Allow-Origin"))
.build();
}
}

当网关的CORS逻辑和下游逻辑同时添加Access-Control-Allow-Credentials和Access-Control-Allow-Origin响应头时,此功能会移除重复值。

DedupeResponseHeader 过滤器还接受一个可选的 strategy 参数。可接受的值为 RETAIN_FIRST(默认)、RETAIN_LAST 和 RETAIN_UNIQUE。