SetRequestHostHeader
フィルター
状況によっては、ホストヘッダーをオーバーライドする必要がある場合があります。この状況では、SetRequestHostHeader
フィルターは既存のホストヘッダーを指定された値に置き換えることができます。フィルターは host
パラメーターを受け取ります。次のリストは、SetRequestHostHeader
フィルターを構成します。
application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: set_request_host_header_route
uri: http://localhost:8080
predicates:
- Path=/headers
filters:
- name: SetRequestHostHeader
args:
host: example.org
GatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.setRequestHostHeader;
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> gatewayRouterFunctionsSetRequestHostHeader() {
return route("set_request_host_header_route")
.GET("/headers", http("http://localhost:8080"))
.before(setRequestHostHeader("example.org"))
.build();
}
}
SetRequestHostHeader
フィルターは、ホストヘッダーの値を example.org
に置き換えます。