4

仅使用 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()
}

效果很好。如果我们将 设置proxiedRemotehttps://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/
4

1 回答 1

0

routes应该让你去那里:

- id: redirect_on_referer
  uri: http://localhost:8081
  predicates:
    - Header=Referer, http://localhost:8081/proxgoo/
  filters:
    - RewritePath=/(?<segment>.*), /proxgoo/$\{segment}
于 2020-09-10T10:59:59.283 回答