AddResponseHeader GatewayFilter Factory

The AddResponseHeader GatewayFilter Factory takes three parameters: name, value and override(default value is true) . The following example configures an AddResponseHeader GatewayFilter:

application.yml
spring:
  cloud:
    gateway:
      routes:
      - id: add_response_header_route
        uri: https://example.org
        filters:
        - AddResponseHeader=X-Response-Red, Blue
        - AddResponseHeader=X-Response-Black, White, false

This adds X-Response-Red:Blue header to the downstream response’s headers for all matching requests. and if the response already contains the X-Response-Black header, this will not add the X-Response-Black: White header to the downstream response’s headers for all matching requests.

AddResponseHeader is aware of URI variables used to match a path or host. URI variables may be used in the value and are expanded at runtime. The following example configures an AddResponseHeader GatewayFilter that uses a variable:

application.yml
spring:
  cloud:
    gateway:
      routes:
      - id: add_response_header_route
        uri: https://example.org
        predicates:
        - Host: {segment}.myhost.org
        filters:
        - AddResponseHeader=foo, bar-{segment}