Java SpringGateway:如何根据请求头和路径动态设置URI和路径
假设我有一个传入请求: 主机:Java SpringGateway:如何根据请求头和路径动态设置URI和路径,java,spring,spring-boot,spring-cloud,spring-cloud-gateway,Java,Spring,Spring Boot,Spring Cloud,Spring Cloud Gateway,假设我有一个传入请求: 主机:my XXX.domain.com和路径/YYY/ZZZ,我想将该请求路由到uriXXX.YYY.internal.domain.com/ZZZ。我怎样才能做到呢 标准api似乎不允许任何类型的模式提取 builder.routes() .route{ it .header(xxx,xxx) .path("/*/**") .uri("i can't use here anything c
my XXX.domain.com
和路径/YYY/ZZZ
,我想将该请求路由到uriXXX.YYY.internal.domain.com/ZZZ
。我怎样才能做到呢
标准api似乎不允许任何类型的模式提取
builder.routes()
.route{ it
.header(xxx,xxx)
.path("/*/**")
.uri("i can't use here anything captured in header or path function")
}
有一个函数允许我访问请求并允许返回任何URI
.filters{
it.changeRequestUri {
val service = it.request....
Optional.of(URI("http://...."))
}
}
.uri("https://this will be ignored")
但我无法在那里设定路径
是否有任何现有的api可以简单地实现它,或者我必须编写自定义过滤器?如何正确地做这件事?这对我来说很有用
.filters{
it.changeRequestUri {
val (service, environment, newPath) = computeUrlParts(it)
Optional.of(URI("http://$environment$service.internal.my-company.com/$newPath"))
}
}
.uri("http://postman-echo.com") //ignored
这就是我的工作
.filters{
it.changeRequestUri {
val (service, environment, newPath) = computeUrlParts(it)
Optional.of(URI("http://$environment$service.internal.my-company.com/$newPath"))
}
}
.uri("http://postman-echo.com") //ignored
uri属性不应包含路径。使用诸如
SetPath
或RewritePath
之类的筛选器来更改路径。@SpencergibSetPath
和RewritePath
都不允许根据输入路径设置路径,或者它们不允许设置路径。这里是重写和设置路径。您还可以在host()
谓词中执行路径{myval}
。uri属性不应包含路径。使用诸如SetPath
或RewritePath
之类的筛选器来更改路径。@SpencergibSetPath
和RewritePath
都不允许根据输入路径设置路径,或者它们不允许设置路径。这里是重写和设置路径。您还可以在host()
谓词中执行路径{myval}
。