Spring Cloud Gateway: Gateway Filter (GatewayFilter) factory

Route filters allow to modify incoming HTTP requests or outgoing HTTP responses in some way. Route filters apply only to specific routes. Spring Cloud Gateway includes a number of built-in gateway filter factories.

For a more detailed example of how to use any of the filters below, check out the unit tests.

1. AddRequestHeader GatewayFilter factory

AddRequestHeader GatewayFilter factory (add request header gateway filter factory) accepts name and value two parameters. Here is an example of configuring AddRequestHeader GatewayFilter:

application.yml

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

This configuration adds the request header "X-Request-red: blue" to the header of the downstream request for all matching requests.

The AddRequestHeader filter recognizes URI variables for matching paths or hosts. URI variables can be used in value and expanded at runtime. Here is an example of configuring AddRequestHeader GatewayFilter using variables:

application.yml

spring:
  cloud:
    gateway:
      routes:
      - id: add_request_header_route
        uri: https://example.org
        predicates:
        - Path=/re

Guess you like

Origin blog.csdn.net/qq_29901385/article/details/131314070