Spring Cloud Gateway 文档笔记

前言

Spring Cloud Gateway旨在提供一种简单而有效的方式来路由api,并为它们提供切入点,如:安全性、监控/度量和弹性。

1. 引入

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

2. 术语

Route:构建网关的基础,包含一个id,一个uri,一组断言(predicates)和一组过滤器(Filter)。断言组合如果为true,则路由匹配。

Predicate:实际上就是 Java 8 中 Predicate 接口的实例,输入类型为 ServerWebExchange。通过他可以匹配来自HTTP请求的任何内容,例如头或参数。

Filter:Spring Cloud 中 GatewayFilter 接口的实例,由特定的工厂类创建。

注:ServerWebExchange:Since 5.0,提供对HTTP请求和响应的访问。

3. 工作流程:

客户端向Spring Cloud Gateway 发出请求。如果网关处理程序映射确定请求与路由匹配,则将请求发送到网关 Web 处理程序。此处理程序通过特定的过滤器链运行请求。过滤器被虚线分隔的原因是:过滤器可以在发送代理请求之前和之后运行“pre”过滤逻辑。然后发出代理请求。发出代理请求后,将运行“post”过滤逻辑。

4. 配置断言和过滤

4.1. 快捷配置

spring:
  cloud:
    gateway:
      routes:
      - id: after_route
        uri: https://example.org
        predicates:
        - Cookie=mycookie,mycookievalue

4.2. 完整配置

spring:
  cloud:
    gateway:
      routes:
      - id: after_route
        uri: https://example.org
        predicates:
        - name: Cookie
          args:
            name: mycookie
            regexp: mycookievalue

5. 路由断言

5.1. After断言

spring:
  cloud:
    gateway:
      routes:
      - id: after_route
        uri: https://example.org
        predicates:
        - After=2017-01-20T17:42:47.789-07:00[America/Denver]

5.2. Before断言

spring:
  cloud:
    gateway:
      routes:
      - id: before_route
        uri: https://example.org
        predicates:
        - Before=2017-01-20T17:42:47.789-07:00[America/Denver]

5.3. Between断言

spring:
  cloud:
    gateway:
      routes:
      - id: between_route
        uri: https://example.org
        predicates:
        - Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]

5.4. Cookie断言

spring:
  cloud:
    gateway:
      routes:
      - id: cookie_route
        uri: https://example.org
        predicates:
        - Cookie=chocolate, ch.p

5.5. Header断言

spring:
  cloud:
    gateway:
      routes:
      - id: header_route
        uri: https://example.org
        predicates:
        - Header=X-Request-Id, \d+

5.6. Host断言

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

URI 模板参数也是支持的,比如:{sub}.myhost.org,可以匹配 Header 中 Host 是 www.somehost.org 和beta.somehost.org。这些模板参数会被存储起来,在后面的过滤器链中可以通过 ServerWebExchange.getAttributes() 方法取到,key值是 ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE。

5.7. Method断言

spring:
  cloud:
    gateway:
      routes:
      - id: method_route
        uri: https://example.org
        predicates:
        - Method=GET,POST

5.8. Path断言

spring:
  cloud:
    gateway:
      routes:
      - id: path_route
        uri: https://example.org
        predicates:
        - Path=/red/{segment},/blue/{segment}

如果 matchTrailingSlash 设置为 false 的话,则请求路径 /red/1/ 是不匹配上面的路由的。

这些模板参数一样会会被存储起来,在后面的过滤器链中可以通过 ServerWebExchange.getAttributes() 方法取到,key 值是 ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE。

下面是一个例子:

Map<String, String> uriVariables = ServerWebExchangeUtils.getPathPredicateVariables(exchange);
String segment = uriVariables.get("segment");

5.9. Path断言

spring:
  cloud:
    gateway:
      routes:
      - id: query_route
        uri: https://example.org
        predicates:
        - Query=red, gree.

gree. 是一个 regexp ,green、greet 都是匹配这个表达式的。

5.10. RemoteAddr断言

spring:
  cloud:
    gateway:
      routes:
      - id: remoteaddr_route
        uri: https://example.org
        predicates:
        - RemoteAddr=192.168.1.1/24

5.11. 修改 RemoteAddr 的解析方式

如果 Spring Cloud Gateway 在一个代理服务的后面,那么拿到的 RemoteAddr 可能不是真实的。可以通过自定义一个 RemoteAddressResolver 来解析出真实的 RemoteAddr 。Spring Cloud Gateway 附带了一个非默认的远程地址解析器 – XForwardedRemoteAddressResolve,它基于 X-Forwarded-For 请求头来解析出真实的远程地址

使用方式:

RemoteAddressResolver resolver = XForwardedRemoteAddressResolver
    .maxTrustedIndex(1);
...
.route("direct-route",
    r -> r.remoteAddr("10.1.1.1", "10.10.1.1/24")
        .uri("https://downstream1")
.route("proxied-route",
    r -> r.remoteAddr(resolver, "10.10.1.1", "10.10.1.1/24")
        .uri("https://downstream2")
)

5.12. Weight断言

spring:
  cloud:
    gateway:
      routes:
      - id: weight_high
        uri: https://weighthigh.org
        predicates:
        - Weight=group1, 8
      - id: weight_low
        uri: https://weightlow.org
        predicates:
        - Weight=group1, 2

Weight断言需要提供两个参数,group 和 weight。

6. GatewayFilter

6.1. AddRequestHeader 过滤器

spring:
  cloud:
    gateway:
      routes:
      - id: add_request_header_route
        uri: https://example.org
        filters:
        - AddRequestHeader=X-Request-red, blue

7. GlobalFilter

8. HttpHeadersFilters

9. TLS and SSL

10. Configuration

Spring Cloud Gateway 的配置是由一组 RouteDefinitionLocator 实例驱动的。默认情况下,PropertiesRouteDefinitionLocator 通过使用 Spring Boot 的 @ConfigurationProperties 机制来加载属性。

下面的两种配置方式是等价的:

spring:
  cloud:
    gateway:
      routes:
      - id: setstatus_route
        uri: https://example.org
        filters:
        - name: SetStatus
          args:
            status: 401
      - id: setstatusshortcut_route
        uri: https://example.org
        filters:
        - SetStatus=401

11. 配置路由元数据

可以使用元数据为每个路由配置额外的参数:

spring:
  cloud:
    gateway:
      routes:
      - id: route_with_metadata
        uri: https://example.org
        metadata:
          optionName: "OptionValue"
          compositeObject:
            name: "value"
          iAmNumber: 1

可以从一个exchange中获取元数据

Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
// get all metadata properties
route.getMetadata();
// get a single metadata property
route.getMetadata(someKey);

12. Http 超时配置

12.1. 全局超时配置

spring:
  cloud:
    gateway:
      httpclient:
        connect-timeout: 1000
        response-timeout: 5s

12.2. 单个路由的超时配置

      - id: per_route_timeouts
        uri: https://example.org
        predicates:
          - name: Path
            args:
              pattern: /delay/{timeout}
        metadata:
          response-timeout: 200
          connect-timeout: 200

也可以用 Java Bean 方式配置,单位都是毫秒。

import static org.springframework.cloud.gateway.support.RouteMetadataUtils.CONNECT_TIMEOUT_ATTR;
import static org.springframework.cloud.gateway.support.RouteMetadataUtils.RESPONSE_TIMEOUT_ATTR;

      @Bean
      public RouteLocator customRouteLocator(RouteLocatorBuilder routeBuilder){
         return routeBuilder.routes()
               .route("test1", r -> {
                  return r.host("*.somehost.org").and().path("/somepath")
                        .filters(f -> f.addRequestHeader("header1", "header-value-1"))
                        .uri("http://someuri")
                        .metadata(RESPONSE_TIMEOUT_ATTR, 200)
                        .metadata(CONNECT_TIMEOUT_ATTR, 200);
               })
               .build();
      }

12.3. 流式 Java API

RouteLocatorBuilder 提供了一套流式的 API,用法如下:

// static imports from GatewayFilters and RoutePredicates
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) {
    return builder.routes()
            .route(r -> r.host("**.abc.org").and().path("/image/png")
                .filters(f ->
                        f.addResponseHeader("X-TestHeader", "foobar"))
                .uri("http://httpbin.org:80")
            )
            .route(r -> r.path("/image/webp")
                .filters(f ->
                        f.addResponseHeader("X-AnotherHeader", "baz"))
                .uri("http://httpbin.org:80")
                .metadata("key", "value")
            )
            .route(r -> r.order(-1)
                .host("**.throttle.org").and().path("/get")
                .filters(f -> f.filter(throttle.apply(1,
                        1,
                        10,
                        TimeUnit.SECONDS)))
                .uri("http://httpbin.org:80")
                .metadata("key", "value")
            )
            .build();
}

不仅可以用 and() 连接,还可以用 or(),negate()。

12.4. 服务发现路由配置

开启方式:

spring.cloud.gateway.discovery.locator.enabled=true

12.4.1. 配置路由,指向注册中心中的其他服务

默认情况下,网关为使用DiscoveryClient创建的路由定义一个单独的断言和过滤器。默认的断言是一个 Path 断言,模式是:/serviceId/**,serviceId 就是注册中心中的服务 id。

默认的 filter 是一个 rewrite path filter,表达式是:/serviceId/?(?.*),重写成:/${remaining}。从而在请求发送到下游之前从路径中剥离服务ID。

如果想自定义,可以通过以下参数配置生效:

#spring.cloud.gateway.discovery.locator.predicates[x]
#spring.cloud.gateway.discovery.locator.filters[y]
spring.cloud.gateway.discovery.locator.predicates[0].name: Path
spring.cloud.gateway.discovery.locator.predicates[0].args[pattern]: "'/'+serviceId+'/**'"
spring.cloud.gateway.discovery.locator.predicates[1].name: Host
spring.cloud.gateway.discovery.locator.predicates[1].args[pattern]: "'**.foo.com'"
spring.cloud.gateway.discovery.locator.filters[0].name: CircuitBreaker
spring.cloud.gateway.discovery.locator.filters[0].args[name]: serviceId
spring.cloud.gateway.discovery.locator.filters[1].name: RewritePath
spring.cloud.gateway.discovery.locator.filters[1].args[regexp]: "'/' + serviceId + '/?(?<remaining>.*)'"
spring.cloud.gateway.discovery.locator.filters[1].args[replacement]: "'/${remaining}'"

13. Reactor Netty Access Logs

开启 Reactor Netty 日志的设置是:-Dreactor.netty.http.server.accessLogEnabled=true

注意这是一个 JVM 配置。

logback 示例配置:

    <appender name="accessLog" class="ch.qos.logback.core.FileAppender">
        <file>access_log.log</file>
        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>
    <appender name="async" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="accessLog" />
    </appender>

    <logger name="reactor.netty.http.server.AccessLog" level="INFO" additivity="false">
        <appender-ref ref="async"/>
    </logger>

14. CORS Configuration

可以通过配置 Gateway 控制 CORS 行为。下面是一个全局的 CORS 配置示例:

spring:
  cloud:
    gateway:
      globalcors:
        cors-configurations:
          '[/**]':
            allowedOrigins: "https://docs.spring.io"
            allowedMethods:
            - GET

要为没有被网关路由断言处理的请求提供相同的 CORS 配置,请设置下面属性为 true。

spring.cloud.gateway.globalcors.add-to-simple-url-handler-mapping=true

这个设置也可以用来支撑 CORS 预检查接口,(预检查接口的请求类型是 options)。

15. Actuator API

下面的配置可以开启 /gateway 端点,

management.endpoint.gateway.enabled=true # default value
management.endpoints.web.exposure.include=gateway

15.1. 检索路由

/actuator/gateway/routes

访问这个端点可以展示详细的 route 信息?

不想暴露详细的 route 信息可以通过以下配置关闭:

spring.cloud.gateway.actuator.verbose.enabled=false

15.2. 检索过滤器

15.2.1. 检索全局过滤器

/actuator/gateway/globalfilters

15.2.2. 检索路由过滤器

/actuator/gateway/routefilters

15.3. 刷新 Route 缓存

/actuator/gateway/refresh,POST

15.4. 检索路由配置

/actuator/gateway/routes

15.5. 检索单个路由配置

/actuator/gateway/routes/{id}

15.6. 创建或者删除单个路由配置

/gateway/routes/{id_route_to_create},POST

/gateway/routes/{id_route_to_create},DELETE

15.7. 所有端点的列表

ID HTTP Method Description
globalfilters GET Displays the list of global filters applied to the routes.
routefilters GET Displays the list of GatewayFilter factories applied to a particular route.
refresh POST Clears the routes cache.
routes GET Displays the list of routes defined in the gateway.
routes/{id} GET Displays information about a particular route.
routes/{id} POST Adds a new route to the gateway.
routes/{id} DELETE Removes an existing route from the gateway

16. 故障排除

17. 开发者指南

17.1. 自定义断言

17.2. 自定义 GatewayFilter

17.3. 自定义 GlobalFilter

18. 使用 Spring MVC 或者 Webflux 创建一个简单的网关

19. 配置项

Name Default Description
spring.cloud.gateway.default-filters List of filter definitions that are applied to every route.
spring.cloud.gateway.discovery.locator.enabled false Flag that enables DiscoveryClient gateway integration.
spring.cloud.gateway.discovery.locator.filters
spring.cloud.gateway.discovery.locator.include-expression true SpEL expression that will evaluate whether to include a service in gateway integration or not, defaults to: true.
spring.cloud.gateway.discovery.locator.lower-case-service-id false Option to lower case serviceId in predicates and filters, defaults to false. Useful with eureka when it automatically uppercases serviceId. so MYSERIVCE, would match /myservice/**
spring.cloud.gateway.discovery.locator.predicates
spring.cloud.gateway.discovery.locator.route-id-prefix The prefix for the routeId, defaults to discoveryClient.getClass().getSimpleName() + _. Service Id will be appended to create the routeId.
spring.cloud.gateway.discovery.locator.url-expression ‘lb://’+serviceId SpEL expression that create the uri for each route, defaults to: ‘lb://’+serviceId.
spring.cloud.gateway.enabled true Enables gateway functionality.
spring.cloud.gateway.fail-on-route-definition-error true Option to fail on route definition errors, defaults to true. Otherwise, a warning is logged.
spring.cloud.gateway.filter.add-request-header.enabled true Enables the add-request-header filter.
spring.cloud.gateway.filter.add-request-parameter.enabled true Enables the add-request-parameter filter.
spring.cloud.gateway.filter.add-response-header.enabled true Enables the add-response-header filter.
spring.cloud.gateway.filter.circuit-breaker.enabled true Enables the circuit-breaker filter.
spring.cloud.gateway.filter.dedupe-response-header.enabled true Enables the dedupe-response-header filter.
spring.cloud.gateway.filter.fallback-headers.enabled true Enables the fallback-headers filter.
spring.cloud.gateway.filter.hystrix.enabled true Enables the hystrix filter.
spring.cloud.gateway.filter.map-request-header.enabled true Enables the map-request-header filter.
spring.cloud.gateway.filter.modify-request-body.enabled true Enables the modify-request-body filter.
spring.cloud.gateway.filter.modify-response-body.enabled true Enables the modify-response-body filter.
spring.cloud.gateway.filter.prefix-path.enabled true Enables the prefix-path filter.
spring.cloud.gateway.filter.preserve-host-header.enabled true Enables the preserve-host-header filter.
spring.cloud.gateway.filter.redirect-to.enabled true Enables the redirect-to filter.
spring.cloud.gateway.filter.remove-hop-by-hop.headers
spring.cloud.gateway.filter.remove-hop-by-hop.order
spring.cloud.gateway.filter.remove-request-header.enabled true Enables the remove-request-header filter.
spring.cloud.gateway.filter.remove-request-parameter.enabled true Enables the remove-request-parameter filter.
spring.cloud.gateway.filter.remove-response-header.enabled true Enables the remove-response-header filter.
spring.cloud.gateway.filter.request-header-size.enabled true Enables the request-header-size filter.
spring.cloud.gateway.filter.request-header-to-request-uri.enabled true Enables the request-header-to-request-uri filter.
spring.cloud.gateway.filter.request-rate-limiter.deny-empty-key true Switch to deny requests if the Key Resolver returns an empty key, defaults to true.
spring.cloud.gateway.filter.request-rate-limiter.empty-key-status-code HttpStatus to return when denyEmptyKey is true, defaults to FORBIDDEN.
spring.cloud.gateway.filter.request-rate-limiter.enabled true Enables the request-rate-limiter filter.
spring.cloud.gateway.filter.request-size.enabled true Enables the request-size filter.
spring.cloud.gateway.filter.retry.enabled true Enables the retry filter.
spring.cloud.gateway.filter.rewrite-location-response-header.enabled true Enables the rewrite-location-response-header filter.
spring.cloud.gateway.filter.rewrite-location.enabled true Enables the rewrite-location filter.
spring.cloud.gateway.filter.rewrite-path.enabled true Enables the rewrite-path filter.
spring.cloud.gateway.filter.rewrite-response-header.enabled true Enables the rewrite-response-header filter.
spring.cloud.gateway.filter.save-session.enabled true Enables the save-session filter.
spring.cloud.gateway.filter.secure-headers.content-security-policy default-src ‘self’ https:; font-src ‘self’ https: data:; img-src ‘self’ https: data:; object-src ‘none’; script-src https:; style-src ‘self’ https: ‘unsafe-inline’
spring.cloud.gateway.filter.secure-headers.content-type-options nosniff
spring.cloud.gateway.filter.secure-headers.disable
spring.cloud.gateway.filter.secure-headers.download-options noopen
spring.cloud.gateway.filter.secure-headers.enabled true Enables the secure-headers filter.
spring.cloud.gateway.filter.secure-headers.frame-options DENY
spring.cloud.gateway.filter.secure-headers.permitted-cross-domain-policies none
spring.cloud.gateway.filter.secure-headers.referrer-policy no-referrer
spring.cloud.gateway.filter.secure-headers.strict-transport-security max-age=631138519
spring.cloud.gateway.filter.secure-headers.xss-protection-header 1 ; mode=block
spring.cloud.gateway.filter.set-path.enabled true Enables the set-path filter.
spring.cloud.gateway.filter.set-request-header.enabled true Enables the set-request-header filter.
spring.cloud.gateway.filter.set-request-host-header.enabled true Enables the set-request-host-header filter.
spring.cloud.gateway.filter.set-response-header.enabled true Enables the set-response-header filter.
spring.cloud.gateway.filter.set-status.enabled true Enables the set-status filter.
spring.cloud.gateway.filter.strip-prefix.enabled true Enables the strip-prefix filter.
spring.cloud.gateway.forwarded.enabled true Enables the ForwardedHeadersFilter.
spring.cloud.gateway.global-filter.adapt-cached-body.enabled true Enables the adapt-cached-body global filter.
spring.cloud.gateway.global-filter.forward-path.enabled true Enables the forward-path global filter.
spring.cloud.gateway.global-filter.forward-routing.enabled true Enables the forward-routing global filter.
spring.cloud.gateway.global-filter.load-balancer-client.enabled true Enables the load-balancer-client global filter.
spring.cloud.gateway.global-filter.netty-routing.enabled true Enables the netty-routing global filter.
spring.cloud.gateway.global-filter.netty-write-response.enabled true Enables the netty-write-response global filter.
spring.cloud.gateway.global-filter.reactive-load-balancer-client.enabled true Enables the reactive-load-balancer-client global filter.
spring.cloud.gateway.global-filter.remove-cached-body.enabled true Enables the remove-cached-body global filter.
spring.cloud.gateway.global-filter.route-to-request-url.enabled true Enables the route-to-request-url global filter.
spring.cloud.gateway.global-filter.websocket-routing.enabled true Enables the websocket-routing global filter.
spring.cloud.gateway.globalcors.add-to-simple-url-handler-mapping false If global CORS config should be added to the URL handler.
spring.cloud.gateway.globalcors.cors-configurations
spring.cloud.gateway.httpclient.compression false Enables compression for Netty HttpClient.
spring.cloud.gateway.httpclient.connect-timeout The connect timeout in millis, the default is 45s.
spring.cloud.gateway.httpclient.max-header-size The max response header size.
spring.cloud.gateway.httpclient.max-initial-line-length The max initial line length.
spring.cloud.gateway.httpclient.pool.acquire-timeout Only for type FIXED, the maximum time in millis to wait for aquiring.
spring.cloud.gateway.httpclient.pool.max-connections Only for type FIXED, the maximum number of connections before starting pending acquisition on existing ones.
spring.cloud.gateway.httpclient.pool.max-idle-time Time in millis after which the channel will be closed. If NULL, there is no max idle time.
spring.cloud.gateway.httpclient.pool.max-life-time Duration after which the channel will be closed. If NULL, there is no max life time.
spring.cloud.gateway.httpclient.pool.name proxy The channel pool map name, defaults to proxy.
spring.cloud.gateway.httpclient.pool.type Type of pool for HttpClient to use, defaults to ELASTIC.
spring.cloud.gateway.httpclient.proxy.host Hostname for proxy configuration of Netty HttpClient.
spring.cloud.gateway.httpclient.proxy.non-proxy-hosts-pattern Regular expression (Java) for a configured list of hosts. that should be reached directly, bypassing the proxy
spring.cloud.gateway.httpclient.proxy.password Password for proxy configuration of Netty HttpClient.
spring.cloud.gateway.httpclient.proxy.port Port for proxy configuration of Netty HttpClient.
spring.cloud.gateway.httpclient.proxy.type proxyType for proxy configuration of Netty HttpClient.
spring.cloud.gateway.httpclient.proxy.username Username for proxy configuration of Netty HttpClient.
spring.cloud.gateway.httpclient.response-timeout The response timeout.
spring.cloud.gateway.httpclient.ssl.close-notify-flush-timeout 3000ms SSL close_notify flush timeout. Default to 3000 ms.
spring.cloud.gateway.httpclient.ssl.close-notify-read-timeout 0 SSL close_notify read timeout. Default to 0 ms.
spring.cloud.gateway.httpclient.ssl.default-configuration-type The default ssl configuration type. Defaults to TCP.
spring.cloud.gateway.httpclient.ssl.handshake-timeout 10000ms SSL handshake timeout. Default to 10000 ms
spring.cloud.gateway.httpclient.ssl.key-password Key password, default is same as keyStorePassword.
spring.cloud.gateway.httpclient.ssl.key-store Keystore path for Netty HttpClient.
spring.cloud.gateway.httpclient.ssl.key-store-password Keystore password.
spring.cloud.gateway.httpclient.ssl.key-store-provider Keystore provider for Netty HttpClient, optional field.
spring.cloud.gateway.httpclient.ssl.key-store-type JKS Keystore type for Netty HttpClient, default is JKS.
spring.cloud.gateway.httpclient.ssl.trusted-x509-certificates Trusted certificates for verifying the remote endpoint’s certificate.
spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager false Installs the netty InsecureTrustManagerFactory. This is insecure and not suitable for production.
spring.cloud.gateway.httpclient.websocket.max-frame-payload-length Max frame payload length.
spring.cloud.gateway.httpclient.websocket.proxy-ping true Proxy ping frames to downstream services, defaults to true.
spring.cloud.gateway.httpclient.wiretap false Enables wiretap debugging for Netty HttpClient.
spring.cloud.gateway.httpserver.wiretap false Enables wiretap debugging for Netty HttpServer.
spring.cloud.gateway.loadbalancer.use404 false
spring.cloud.gateway.metrics.enabled false Enables the collection of metrics data.
spring.cloud.gateway.metrics.prefix spring.cloud.gateway The prefix of all metrics emitted by gateway.
spring.cloud.gateway.metrics.tags Tags map that added to metrics.
spring.cloud.gateway.predicate.after.enabled true Enables the after predicate.
spring.cloud.gateway.predicate.before.enabled true Enables the before predicate.
spring.cloud.gateway.predicate.between.enabled true Enables the between predicate.
spring.cloud.gateway.predicate.cloud-foundry-route-service.enabled true Enables the cloud-foundry-route-service predicate.
spring.cloud.gateway.predicate.cookie.enabled true Enables the cookie predicate.
spring.cloud.gateway.predicate.header.enabled true Enables the header predicate.
spring.cloud.gateway.predicate.host.enabled true Enables the host predicate.
spring.cloud.gateway.predicate.method.enabled true Enables the method predicate.
spring.cloud.gateway.predicate.path.enabled true Enables the path predicate.
spring.cloud.gateway.predicate.query.enabled true Enables the query predicate.
spring.cloud.gateway.predicate.read-body.enabled true Enables the read-body predicate.
spring.cloud.gateway.predicate.remote-addr.enabled true Enables the remote-addr predicate.
spring.cloud.gateway.predicate.weight.enabled true Enables the weight predicate.
spring.cloud.gateway.redis-rate-limiter.burst-capacity-header X-RateLimit-Burst-Capacity The name of the header that returns the burst capacity configuration.
spring.cloud.gateway.redis-rate-limiter.config
spring.cloud.gateway.redis-rate-limiter.include-headers true Whether or not to include headers containing rate limiter information, defaults to true.
spring.cloud.gateway.redis-rate-limiter.remaining-header X-RateLimit-Remaining The name of the header that returns number of remaining requests during the current second.
spring.cloud.gateway.redis-rate-limiter.replenish-rate-header X-RateLimit-Replenish-Rate The name of the header that returns the replenish rate configuration.
spring.cloud.gateway.redis-rate-limiter.requested-tokens-header X-RateLimit-Requested-Tokens The name of the header that returns the requested tokens configuration.
spring.cloud.gateway.routes List of Routes.
spring.cloud.gateway.set-status.original-status-header-name The name of the header which contains http code of the proxied request.
spring.cloud.gateway.streaming-media-types
spring.cloud.gateway.x-forwarded.enabled true If the XForwardedHeadersFilter is enabled.
spring.cloud.gateway.x-forwarded.for-append true If appending X-Forwarded-For as a list is enabled.
spring.cloud.gateway.x-forwarded.for-enabled true If X-Forwarded-For is enabled.
spring.cloud.gateway.x-forwarded.host-append true If appending X-Forwarded-Host as a list is enabled.
spring.cloud.gateway.x-forwarded.host-enabled true If X-Forwarded-Host is enabled.
spring.cloud.gateway.x-forwarded.order 0 The order of the XForwardedHeadersFilter.
spring.cloud.gateway.x-forwarded.port-append true If appending X-Forwarded-Port as a list is enabled.
spring.cloud.gateway.x-forwarded.port-enabled true If X-Forwarded-Port is enabled.
spring.cloud.gateway.x-forwarded.prefix-append true If appending X-Forwarded-Prefix as a list is enabled.
spring.cloud.gateway.x-forwarded.prefix-enabled true If X-Forwarded-Prefix is enabled.
spring.cloud.gateway.x-forwarded.proto-append true If appending X-Forwarded-Proto as a list is enabled.
spring.cloud.gateway.x-forwarded.proto-enabled true If X-Forwarded-Proto is enabled.

原文:Spring Cloud Gateway 文档笔记 | kun's blog