PreserveHostHeader フィルター

PreserveHostHeader フィルターにはパラメーターがありません。このフィルターは、HTTP クライアントによって決定されたホストヘッダーではなく、元のホストヘッダーを送信する必要があるかどうかを決定するために HandlerFunction がインスペクションするリクエスト属性を設定します。次の例では、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();
    }
}