DedupeResponseHeader フィルター

DedupeResponseHeader GatewayFilter ファクトリは、name パラメーターとオプションの strategy パラメーターを受け取ります。name には、スペースで区切られたヘッダー名のリストを含めることができます。次の例では、DedupeResponseHeader フィルターを構成します。

application.yml
spring:
  cloud:
    gateway:
      mvc:
        routes:
        - id: dedupe_response_header_route
          uri: https://example.org
          filters:
          - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
GatewaySampleApplication.java
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();
    }
}

これにより、ゲートウェイ CORS ロジックとダウンストリームロジックの両方が追加した場合に、Access-Control-Allow-Credentials および Access-Control-Allow-Origin レスポンスヘッダーの重複値が削除されます。

DedupeResponseHeader フィルターは、オプションの strategy パラメーターも受け入れます。受け入れられる値は、RETAIN_FIRST (デフォルト)、RETAIN_LASTRETAIN_UNIQUE です。