最新の安定バージョンについては、Spring Cloud Gateway 4.3.2 を使用してください! |
DedupeResponseHeader フィルター
DedupeResponseHeader GatewayFilter ファクトリは、name パラメーターとオプションの strategy パラメーターを受け取ります。name には、スペースで区切られたヘッダー名のリストを含めることができます。次の例では、DedupeResponseHeader フィルターを構成します。
application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: dedupe_response_header_route
uri: https://example.org
predicates:
- Path=/hello
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-OriginGatewaySampleApplication.java
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 です。