RewriteLocationResponseHeader GatewayFilter 工厂

RewriteLocationResponseHeader GatewayFilter 工厂修改 Location 响应头的值,通常是为了去除后端特有的详细信息。它接受 ModelocationHeaderNamehostValueprotocols 参数。以下列表配置了一个 RewriteLocationResponseHeader GatewayFilter

application.yml
spring:
  cloud:
    gateway:
      routes:
      - id: rewritelocationresponseheader_route
        uri: http://example.org
        filters:
        - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, ,

例如,对于 POST api.example.com/some/object/name 的请求,Location 响应头的值 object-service.prod.example.net/v2/some/object/id 被重写为 api.example.com/some/object/id

Mode 参数有以下可能的值:NEVER_STRIPAS_IN_REQUEST (默认) 和 ALWAYS_STRIP

  • NEVER_STRIP:即使原始请求路径不包含版本,版本也不会被剥离。

  • AS_IN_REQUEST:仅当原始请求路径不包含版本时,版本才会被剥离。

  • ALWAYS_STRIP:版本总是被剥离,即使原始请求路径包含版本。

如果提供了 hostValue 参数,它将用于替换响应 Location 头的 host:port 部分。如果未提供,则使用 Host 请求头的值。

protocols 参数必须是有效的正则表达式 String,协议名称将对照其进行匹配。如果未匹配,则过滤器不执行任何操作。默认值为 https?|ftps?

© . This site is unofficial and not affiliated with VMware.