【发布时间】:2018-10-10 11:17:31
【问题描述】:
仅使用 Spring Cloud Gateway,我目前正在使用以下路由(在 Kotlin 中定义)代理远程站点:
@GetMapping("/proxgoo/**")
@Throws(Exception::class)
fun proxyPath(proxy: ProxyExchange<*>): ResponseEntity<*> {
val path = proxy.path("/proxgoo/")
return proxy.uri(proxiedRemote.toString() + "/" + path).get()
}
效果很好。如果我们将proxiedRemote 设置为https://www.google.com,在我们尝试加载外部资源(如图像)之前,这将非常有效。
问题是这样的:
http://localhost:8081/logos/doodles/2018/**
真的应该去:
http://localhost:8081/proxgoo/logos/doodles/2018/**
我在想,如果我可以将 Referer 标头为 http://localhost:8081/proxgoo/ 的所有内容重定向回代理路由,那么这就是我所需要的一切:
所以,实际的问题。我认为以下配置将使用请求标头 Referer=http://localhost:8081/proxgoo/ 重定向所有内容,但它没有接受它。我做了什么傻事吗?
spring:
cloud:
gateway:
routes:
- id: redirect_on_referer
predicates:
- Header=Referer,http://localhost:8081/proxgoo/
filters:
- RedirectTo=302, http://localhost:8081/proxgoo/
【问题讨论】:
标签: spring-cloud spring-cloud-gateway