最新の安定バージョンについては、Spring Cloud Gateway 4.3.2 を使用してください! |
PreserveHostHeader フィルター
PreserveHostHeader フィルターにはパラメーターがありません。このフィルターは、HTTP クライアントによって決定されたホストヘッダーではなく、元のホストヘッダーを送信する必要があるかどうかを決定するために HandlerFunction がインスペクションするリクエスト属性を設定します。次の例では、PreserveHostHeader フィルターを構成します。
application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: preserve_host_route
uri: https://example.org
predicates:
- Path=/**
filters:
- PreserveHostHeaderGatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri;
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.preserveHostHeader;
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> gatewayRouterFunctionsPreserveHostHeader() {
return route("preserve_host_route")
.GET("/**", http())
.before(uri("https://example.org"))
.before(preserveHostHeader())
.build();
}
}