Spring Cloud 主機路由謂詞工廠

2024-01-04 17:31 更新

Host Route Predicate Factory采用一個參數(shù):主機名patterns的列表。模式是Ant樣式的模式,以.作為分隔符。該謂詞與匹配模式的Host頭匹配。

application.yml。 

spring:
  cloud:
    gateway:
      routes:
      - id: host_route
        uri: https://example.org
        predicates:
        - Host=**.somehost.org,**.anotherhost.org

還支持URI模板變量,例如{sub}.myhost.org。

如果請求的Host標(biāo)頭的值為www.somehost.orgbeta.somehost.orgwww.anotherhost.org,則此路由將匹配。

該謂詞提取URI模板變量(如上例中定義的sub)作為名稱和值的映射,并使用在ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE中定義的鍵將其放置在ServerWebExchange.getAttributes()中。這些值可供GatewayFilter工廠使用。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號