For the latest stable version, please use Spring Cloud Gateway 4.2.0!

PreserveHostHeader Filter

The PreserveHostHeader filter has no parameters. This filter sets a request attribute that the HandlerFunction inspects to determine if the original host header should be sent rather than the host header determined by the HTTP client. The following example configures a PreserveHostHeader filter:

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();
    }
}