【问题标题】:Spring Cloud Gateway - Redirect Based on HeaderSpring Cloud Gateway - 基于Header的重定向
【发布时间】: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


    【解决方案1】:

    routes 下的这个应该让你去那里:

    - id: redirect_on_referer
      uri: http://localhost:8081
      predicates:
        - Header=Referer, http://localhost:8081/proxgoo/
      filters:
        - RewritePath=/(?<segment>.*), /proxgoo/$\{segment}
    

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 2021-05-19
      • 2018-12-11
      • 2019-12-11
      • 2022-10-19
      • 1970-01-01
      • 2018-12-01
      • 2021-03-31
      • 1970-01-01
      相关资源
      最近更新 更多