PreserveHostHeader
Filter
PreserveHostHeader
过滤器没有参数。此过滤器设置了一个请求属性,HandlerFunction
检查该属性以确定是否应该发送原始 Host 头,而不是由 HTTP 客户端确定的 Host 头。以下示例配置一个 PreserveHostHeader
过滤器:
application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: preserve_host_route
uri: https://example.org
filters:
- PreserveHostHeader
GatewaySampleApplication.java
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("https://example.org"))
.before(preserveHostHeader())
.build();
}
}