StripPrefix
フィルター
StripPrefix
フィルターは 1 つのパラメーター parts
を取ります。parts
パラメーターは、リクエストをダウンストリームに送信する前にリクエストから削除するパス内の部分の数を示します。次のリストは、StripPrefix
フィルターを構成します。
application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: nameRoot
uri: https://nameservice
predicates:
- Path=/name/**
filters:
- StripPrefix=2
GatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.stripPrefix;
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> gatewayRouterFunctionsStripPrefix() {
return route("nameRoot")
.GET("/name/**", http("https://example.org"))
.before(stripPrefix(2))
.build();
}
}
/name/blue/red
へのゲートウェイを介してリクエストが行われると、nameservice
に対して行われたリクエストは nameservice/red (英語)
のようになります。