跳到主要内容

DedupeResponseHeader 过滤器

DeepSeek V3 中英对照 DedupeResponseHeader Filter DedupeResponseHeader Filter

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

spring:
cloud:
gateway:
mvc:
routes:
- id: dedupe_response_header_route
uri: https://example.org
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
yaml
import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.dedupeResponseHeader;
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("https://example.org"))
.after(dedupeResponseHeader("Access-Control-Allow-Credentials Access-Control-Allow-Origin"))
.build();
}
}
java

这将移除在网关 CORS 逻辑和下游逻辑同时添加 Access-Control-Allow-CredentialsAccess-Control-Allow-Origin 响应头时产生的重复值。

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