【发布时间】:2020-05-08 22:24:48
【问题描述】:
假设我有传入请求:
主机:my-XXX.domain.com 和路径 /YYY/ZZZ,我想将该请求路由到 uri XXX.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 可以简单地实现它,还是我必须编写自定义过滤器?应该怎么做呢?
【问题讨论】:
-
uri 属性不应包含路径。使用
SetPath或RewritePath之类的过滤器来更改路径。 -
@spencergibb
SetPath和RewritePath不允许根据传入路径或 uri 设置路径 -
确实如此。这是重写github.com/spring-cloud-samples/spring-cloud-gateway-sample/… 和设置路径cloud.spring.io/spring-cloud-static/spring-cloud-gateway/…。你也可以在
host()谓词中做路径{myval}。
标签: java spring spring-boot spring-cloud spring-cloud-gateway