Spring Cloud Gateway-使用GlobalFilter添加标题

时间:2019-11-30 06:05:19

标签: spring-cloud-gateway

例如

spring:
  cloud:
    gateway:
      routes:
      - id: hystrix_route
        uri: https://xxxxxxxxxxxx.a.run.app
        predicates:
        - Path=/model/**
        filters:
        - name: Hystrix
          args:
            name: fallbackcmd
            fallbackUri: forward:/incaseoffailureusethis
        - RewritePath=/model(?<segment>/?.*), $\{segment}

我希望能够向符合该谓词/ model / **的所有请求添加标头

以下是执行请求以获取标头值的代码的示例(顺便说一句,receiveingURL是目标uri:https://xxxxxxxxxxxx.a.run.app

var url = "http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=";

var token = webClient
    .get()
    .uri(url + receivingURL)
    .header("Metadata-Flavor", "Google")
    .retrieve()
    .bodyToMono(String.class);

仅供参考:用例是网关在GKE中运行,并且某些端点已部署到Cloud Run。

0 个答案:

没有答案