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.