diff --git a/2.1.x/multi/multi__gatewayfilter_factories.html b/2.1.x/multi/multi__gatewayfilter_factories.html index 447bb440..3e7870d3 100644 --- a/2.1.x/multi/multi__gatewayfilter_factories.html +++ b/2.1.x/multi/multi__gatewayfilter_factories.html @@ -240,7 +240,16 @@ and have it applied to all routes.

- Path=/foo/** filters: - RewritePath=/foo/(?<segment>.*), /$\{segment}

-

For a request path of /foo/bar, this will set the path to /bar before making the downstream request. Notice the $\ which is replaced with $ because of the YAML spec.

5.15 RewriteResponseHeader GatewayFilter Factory

The RewriteResponseHeader GatewayFilter Factory takes name, regexp, and replacement parameters. It uses Java regular expressions for a flexible way to rewrite the response header value.

application.yml.  +

For a request path of /foo/bar, this will set the path to /bar before making the downstream request. Notice the $\ which is replaced with $ because of the YAML spec.

5.15 RewriteLocationResponseHeader GatewayFilter Factory

The RewriteLocationResponseHeader GatewayFilter Factory modifies the value of Location response header, usually to get rid of backend specific details. It takes stripVersionMode, locationHeaderName, hostValue, and protocolsRegex parameters.

application.yml.  +

spring:
+  cloud:
+    gateway:
+      routes:
+      - id: rewritelocationresponseheader_route
+        uri: http://example.org
+        filters:
+        - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, ,

+

For example, for a request POST https://api.example.com/some/object/name, Location response header value https://object-service.prod.example.net/v2/some/object/id will be rewritten as https://api.example.com/some/object/id.

Parameter stripVersionMode has the following possible values: NEVER_STRIP, AS_IN_REQUEST (default), ALWAYS_STRIP.

  • NEVER_STRIP - Version will not be stripped, even if the original request path contains no version
  • AS_IN_REQUEST - Version will be stripped only if the original request path contains no version
  • ALWAYS_STRIP - Version will be stripped, even if the original request path contains version

Parameter hostValue, if provided, will be used to replace the host:port portion of the response Location header. If not provided, the value of the Host request header will be used.

Parameter protocolsRegex must be a valid regex String, against which the protocol name will be matched. If not matched, the filter will do nothing. Default is http|https|ftp|ftps.

5.16 RewriteResponseHeader GatewayFilter Factory

The RewriteResponseHeader GatewayFilter Factory takes name, regexp, and replacement parameters. It uses Java regular expressions for a flexible way to rewrite the response header value.

application.yml. 

spring:
   cloud:
     gateway:
@@ -249,7 +258,7 @@ and have it applied to all routes.

uri: https://example.org filters: - RewriteResponseHeader=X-Response-Foo, , password=[^&]+, password=***

-

For a header value of /42?user=ford&password=omg!what&flag=true, it will be set to /42?user=ford&password=***&flag=true after making the downstream request. Please use $\ to mean $ because of the YAML spec.

5.16 SaveSession GatewayFilter Factory

The SaveSession GatewayFilter Factory forces a WebSession::save operation before forwarding the call downstream. This is of particular use when +

For a header value of /42?user=ford&password=omg!what&flag=true, it will be set to /42?user=ford&password=***&flag=true after making the downstream request. Please use $\ to mean $ because of the YAML spec.

5.17 SaveSession GatewayFilter Factory

The SaveSession GatewayFilter Factory forces a WebSession::save operation before forwarding the call downstream. This is of particular use when using something like Spring Session with a lazy data store and need to ensure the session state has been saved before making the forwarded call.

application.yml. 

spring:
   cloud:
@@ -261,7 +270,7 @@ using something like         - Path=/foo/**
         filters:
         - SaveSession

-

If you are integrating Spring Security with Spring Session, and want to ensure security details have been forwarded to the remote process, this is critical.

5.17 SecureHeaders GatewayFilter Factory

The SecureHeaders GatewayFilter Factory adds a number of headers to the response at the recommendation from this blog post.

The following headers are added (allong with default values):

  • X-Xss-Protection:1; mode=block
  • Strict-Transport-Security:max-age=631138519
  • X-Frame-Options:DENY
  • X-Content-Type-Options:nosniff
  • Referrer-Policy:no-referrer
  • 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'
  • X-Download-Options:noopen
  • X-Permitted-Cross-Domain-Policies:none

To change the default values set the appropriate property in the spring.cloud.gateway.filter.secure-headers namespace:

Property to change:

  • xss-protection-header
  • strict-transport-security
  • frame-options
  • content-type-options
  • referrer-policy
  • content-security-policy
  • download-options
  • permitted-cross-domain-policies

To disable the default values set the property spring.cloud.gateway.filter.secure-headers.disable with comma separated values.

Example: spring.cloud.gateway.filter.secure-headers.disable=frame-options,download-options

5.18 SetPath GatewayFilter Factory

The SetPath GatewayFilter Factory takes a path template parameter. It offers a simple way to manipulate the request path by allowing templated segments of the path. This uses the uri templates from Spring Framework. Multiple matching segments are allowed.

application.yml.  +

If you are integrating Spring Security with Spring Session, and want to ensure security details have been forwarded to the remote process, this is critical.

5.18 SecureHeaders GatewayFilter Factory

The SecureHeaders GatewayFilter Factory adds a number of headers to the response at the recommendation from this blog post.

The following headers are added (allong with default values):

  • X-Xss-Protection:1; mode=block
  • Strict-Transport-Security:max-age=631138519
  • X-Frame-Options:DENY
  • X-Content-Type-Options:nosniff
  • Referrer-Policy:no-referrer
  • 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'
  • X-Download-Options:noopen
  • X-Permitted-Cross-Domain-Policies:none

To change the default values set the appropriate property in the spring.cloud.gateway.filter.secure-headers namespace:

Property to change:

  • xss-protection-header
  • strict-transport-security
  • frame-options
  • content-type-options
  • referrer-policy
  • content-security-policy
  • download-options
  • permitted-cross-domain-policies

To disable the default values set the property spring.cloud.gateway.filter.secure-headers.disable with comma separated values.

Example: spring.cloud.gateway.filter.secure-headers.disable=frame-options,download-options

5.19 SetPath GatewayFilter Factory

The SetPath GatewayFilter Factory takes a path template parameter. It offers a simple way to manipulate the request path by allowing templated segments of the path. This uses the uri templates from Spring Framework. Multiple matching segments are allowed.

application.yml. 

spring:
   cloud:
     gateway:
@@ -272,7 +281,7 @@ using something like         - Path=/foo/{segment}
         filters:
         - SetPath=/{segment}

-

For a request path of /foo/bar, this will set the path to /bar before making the downstream request.

5.19 SetRequestHeader GatewayFilter Factory

The SetRequestHeader GatewayFilter Factory takes name and value parameters.

application.yml.  +

For a request path of /foo/bar, this will set the path to /bar before making the downstream request.

5.20 SetRequestHeader GatewayFilter Factory

The SetRequestHeader GatewayFilter Factory takes name and value parameters.

application.yml. 

spring:
   cloud:
     gateway:
@@ -292,7 +301,7 @@ using something like         - Host: {segment}.myhost.org
         filters:
         - SetRequestHeader=foo, bar-{segment}

-

5.20 SetResponseHeader GatewayFilter Factory

The SetResponseHeader GatewayFilter Factory takes name and value parameters.

application.yml.  +

5.21 SetResponseHeader GatewayFilter Factory

The SetResponseHeader GatewayFilter Factory takes name and value parameters.

application.yml. 

spring:
   cloud:
     gateway:
@@ -312,7 +321,7 @@ using something like         - Host: {segment}.myhost.org
         filters:
         - SetResponseHeader=foo, bar-{segment}

-

5.21 SetStatus GatewayFilter Factory

The SetStatus GatewayFilter Factory takes a single status parameter. It must be a valid Spring HttpStatus. It may be the integer value 404 or the string representation of the enumeration NOT_FOUND.

application.yml.  +

5.22 SetStatus GatewayFilter Factory

The SetStatus GatewayFilter Factory takes a single status parameter. It must be a valid Spring HttpStatus. It may be the integer value 404 or the string representation of the enumeration NOT_FOUND.

application.yml. 

spring:
   cloud:
     gateway:
@@ -325,7 +334,7 @@ using something like         uri: https://example.org
         filters:
         - SetStatus=401

-

In either case, the HTTP status of the response will be set to 401.

5.22 StripPrefix GatewayFilter Factory

The StripPrefix GatewayFilter Factory takes one paramter, parts. The parts parameter indicated the number of parts in the path to strip from the request before sending it downstream.

application.yml.  +

In either case, the HTTP status of the response will be set to 401.

5.23 StripPrefix GatewayFilter Factory

The StripPrefix GatewayFilter Factory takes one paramter, parts. The parts parameter indicated the number of parts in the path to strip from the request before sending it downstream.

application.yml. 

spring:
   cloud:
     gateway:
@@ -336,7 +345,7 @@ using something like         - Path=/name/**
         filters:
         - StripPrefix=2

-

When a request is made through the gateway to /name/bar/foo the request made to nameservice will look like http://nameservice/foo.

5.23 Retry GatewayFilter Factory

The Retry GatewayFilter Factory takes retries, statuses, methods, and series as parameters.

  • retries: the number of retries that should be attempted
  • statuses: the HTTP status codes that should be retried, represented using org.springframework.http.HttpStatus
  • methods: the HTTP methods that should be retried, represented using org.springframework.http.HttpMethod
  • series: the series of status codes to be retried, represented using org.springframework.http.HttpStatus.Series

application.yml.  +

When a request is made through the gateway to /name/bar/foo the request made to nameservice will look like http://nameservice/foo.

5.24 Retry GatewayFilter Factory

The Retry GatewayFilter Factory takes retries, statuses, methods, and series as parameters.

  • retries: the number of retries that should be attempted
  • statuses: the HTTP status codes that should be retried, represented using org.springframework.http.HttpStatus
  • methods: the HTTP methods that should be retried, represented using org.springframework.http.HttpMethod
  • series: the series of status codes to be retried, represented using org.springframework.http.HttpStatus.Series

application.yml. 

spring:
   cloud:
     gateway:
@@ -350,7 +359,7 @@ using something like           args:
             retries: 3
             statuses: BAD_GATEWAY

-

[Note]Note

The retry filter does not currently support retrying with a body (e.g. for POST or PUT requests with a body).

[Note]Note

When using the retry filter with a forward: prefixed URL, the target endpoint should be written carefully so that in case of an error it does not do anything that could result in a response being sent to the client and committed. For example, if the target endpoint is an annotated controller, the target controller method should not return ResponseEntity with an error status code. Instead it should throw an Exception, or signal an error, e.g. via a Mono.error(ex) return value, which the retry filter can be configured to handle by retrying.

5.24 RequestSize GatewayFilter Factory

The RequestSize GatewayFilter Factory can restrict a request from reaching the downstream service , when the request size is greater than the permissible limit. The filter takes RequestSize as parameter which is the permissible size limit of the request defined in bytes.

application.yml.  +

[Note]Note

The retry filter does not currently support retrying with a body (e.g. for POST or PUT requests with a body).

[Note]Note

When using the retry filter with a forward: prefixed URL, the target endpoint should be written carefully so that in case of an error it does not do anything that could result in a response being sent to the client and committed. For example, if the target endpoint is an annotated controller, the target controller method should not return ResponseEntity with an error status code. Instead it should throw an Exception, or signal an error, e.g. via a Mono.error(ex) return value, which the retry filter can be configured to handle by retrying.

5.25 RequestSize GatewayFilter Factory

The RequestSize GatewayFilter Factory can restrict a request from reaching the downstream service , when the request size is greater than the permissible limit. The filter takes RequestSize as parameter which is the permissible size limit of the request defined in bytes.

application.yml. 

spring:
   cloud:
     gateway:
@@ -363,7 +372,7 @@ using something like       - name: RequestSize
         args:
           maxSize: 5000000

-

The RequestSize GatewayFilter Factory set the response status as 413 Payload Too Large with a additional header errorMessage when the Request is rejected due to size. Following is an example of such an errorMessage .

errorMessage : Request size is larger than permissible limit. Request size is 6.0 MB where permissible limit is 5.0 MB

[Note]Note

The default Request size will be set to 5 MB if not provided as filter argument in route definition.

5.25 Modify Request Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the request body before it is sent downstream by the Gateway.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
+

The RequestSize GatewayFilter Factory set the response status as 413 Payload Too Large with a additional header errorMessage when the Request is rejected due to size. Following is an example of such an errorMessage .

errorMessage : Request size is larger than permissible limit. Request size is 6.0 MB where permissible limit is 5.0 MB

[Note]Note

The default Request size will be set to 5 MB if not provided as filter argument in route definition.

5.26 Modify Request Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the request body before it is sent downstream by the Gateway.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
 public RouteLocator routes(RouteLocatorBuilder builder) {
     return builder.routes()
         .route("rewrite_request_obj", r -> r.host("*.rewriterequestobj.org")
@@ -389,7 +398,7 @@ using something like public void setMessage(String message) {
         this.message = message;
     }
-}

5.26 Modify Response Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the response body before it is sent back to the Client.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
+}

5.27 Modify Response Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the response body before it is sent back to the Client.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
 public RouteLocator routes(RouteLocatorBuilder builder) {
     return builder.routes()
         .route("rewrite_response_upper", r -> r.host("*.rewriteresponseupper.org")
@@ -397,7 +406,7 @@ using something like class, String.class,
         		    (exchange, s) -> Mono.just(s.toUpperCase()))).uri(uri)
         .build();
-}

5.27 Default Filters

If you would like to add a filter and apply it to all routes you can use spring.cloud.gateway.default-filters. +}

5.28 Default Filters

If you would like to add a filter and apply it to all routes you can use spring.cloud.gateway.default-filters. This property takes a list of filters

application.yml. 

spring:
   cloud:
diff --git a/2.1.x/multi/multi_spring-cloud-gateway.html b/2.1.x/multi/multi_spring-cloud-gateway.html
index 6e472b8d..c4fbaab7 100644
--- a/2.1.x/multi/multi_spring-cloud-gateway.html
+++ b/2.1.x/multi/multi_spring-cloud-gateway.html
@@ -1,3 +1,3 @@
 
       
-   Spring Cloud Gateway

Spring Cloud Gateway


Table of Contents

1. How to Include Spring Cloud Gateway
2. Glossary
3. How It Works
4. Route Predicate Factories
4.1. After Route Predicate Factory
4.2. Before Route Predicate Factory
4.3. Between Route Predicate Factory
4.4. Cookie Route Predicate Factory
4.5. Header Route Predicate Factory
4.6. Host Route Predicate Factory
4.7. Method Route Predicate Factory
4.8. Path Route Predicate Factory
4.9. Query Route Predicate Factory
4.10. RemoteAddr Route Predicate Factory
4.10.1. Modifying the way remote addresses are resolved
5. GatewayFilter Factories
5.1. AddRequestHeader GatewayFilter Factory
5.2. AddRequestParameter GatewayFilter Factory
5.3. AddResponseHeader GatewayFilter Factory
5.4. DedupeResponseHeader GatewayFilter Factory
5.5. Hystrix GatewayFilter Factory
5.6. FallbackHeaders GatewayFilter Factory
5.7. PrefixPath GatewayFilter Factory
5.8. PreserveHostHeader GatewayFilter Factory
5.9. RequestRateLimiter GatewayFilter Factory
5.9.1. Redis RateLimiter
5.10. RedirectTo GatewayFilter Factory
5.11. RemoveHopByHopHeadersFilter GatewayFilter Factory
5.12. RemoveRequestHeader GatewayFilter Factory
5.13. RemoveResponseHeader GatewayFilter Factory
5.14. RewritePath GatewayFilter Factory
5.15. RewriteResponseHeader GatewayFilter Factory
5.16. SaveSession GatewayFilter Factory
5.17. SecureHeaders GatewayFilter Factory
5.18. SetPath GatewayFilter Factory
5.19. SetRequestHeader GatewayFilter Factory
5.20. SetResponseHeader GatewayFilter Factory
5.21. SetStatus GatewayFilter Factory
5.22. StripPrefix GatewayFilter Factory
5.23. Retry GatewayFilter Factory
5.24. RequestSize GatewayFilter Factory
5.25. Modify Request Body GatewayFilter Factory
5.26. Modify Response Body GatewayFilter Factory
5.27. Default Filters
6. Global Filters
6.1. Combined Global Filter and GatewayFilter Ordering
6.2. Forward Routing Filter
6.3. LoadBalancerClient Filter
6.4. Netty Routing Filter
6.5. Netty Write Response Filter
6.6. RouteToRequestUrl Filter
6.7. Websocket Routing Filter
6.8. Gateway Metrics Filter
6.9. Marking An Exchange As Routed
7. TLS / SSL
7.1. TLS Handshake
8. Configuration
8.1. Fluent Java Routes API
8.2. DiscoveryClient Route Definition Locator
8.2.1. Configuring Predicates and Filters For DiscoveryClient Routes
9. Reactor Netty Access Logs
10. CORS Configuration
11. Actuator API
11.1. Verbose Actuator Format
11.2. Retrieving route filters
11.2.1. Global Filters
11.2.2. Route Filters
11.3. Refreshing the route cache
11.4. Retrieving the routes defined in the gateway
11.5. Retrieving information about a particular route
11.6. Creating and deleting a particular route
11.7. Recap: list of all endpoints
12. Troubleshooting
12.1. Log Levels
12.2. Wiretap
13. Developer Guide
13.1. Writing Custom Route Predicate Factories
13.2. Writing Custom GatewayFilter Factories
13.3. Writing Custom Global Filters
13.4. Writing Custom Route Locators and Writers
14. Building a Simple Gateway Using Spring MVC or Webflux
\ No newline at end of file + Spring Cloud Gateway

Spring Cloud Gateway


Table of Contents

1. How to Include Spring Cloud Gateway
2. Glossary
3. How It Works
4. Route Predicate Factories
4.1. After Route Predicate Factory
4.2. Before Route Predicate Factory
4.3. Between Route Predicate Factory
4.4. Cookie Route Predicate Factory
4.5. Header Route Predicate Factory
4.6. Host Route Predicate Factory
4.7. Method Route Predicate Factory
4.8. Path Route Predicate Factory
4.9. Query Route Predicate Factory
4.10. RemoteAddr Route Predicate Factory
4.10.1. Modifying the way remote addresses are resolved
5. GatewayFilter Factories
5.1. AddRequestHeader GatewayFilter Factory
5.2. AddRequestParameter GatewayFilter Factory
5.3. AddResponseHeader GatewayFilter Factory
5.4. DedupeResponseHeader GatewayFilter Factory
5.5. Hystrix GatewayFilter Factory
5.6. FallbackHeaders GatewayFilter Factory
5.7. PrefixPath GatewayFilter Factory
5.8. PreserveHostHeader GatewayFilter Factory
5.9. RequestRateLimiter GatewayFilter Factory
5.9.1. Redis RateLimiter
5.10. RedirectTo GatewayFilter Factory
5.11. RemoveHopByHopHeadersFilter GatewayFilter Factory
5.12. RemoveRequestHeader GatewayFilter Factory
5.13. RemoveResponseHeader GatewayFilter Factory
5.14. RewritePath GatewayFilter Factory
5.15. RewriteLocationResponseHeader GatewayFilter Factory
5.16. RewriteResponseHeader GatewayFilter Factory
5.17. SaveSession GatewayFilter Factory
5.18. SecureHeaders GatewayFilter Factory
5.19. SetPath GatewayFilter Factory
5.20. SetRequestHeader GatewayFilter Factory
5.21. SetResponseHeader GatewayFilter Factory
5.22. SetStatus GatewayFilter Factory
5.23. StripPrefix GatewayFilter Factory
5.24. Retry GatewayFilter Factory
5.25. RequestSize GatewayFilter Factory
5.26. Modify Request Body GatewayFilter Factory
5.27. Modify Response Body GatewayFilter Factory
5.28. Default Filters
6. Global Filters
6.1. Combined Global Filter and GatewayFilter Ordering
6.2. Forward Routing Filter
6.3. LoadBalancerClient Filter
6.4. Netty Routing Filter
6.5. Netty Write Response Filter
6.6. RouteToRequestUrl Filter
6.7. Websocket Routing Filter
6.8. Gateway Metrics Filter
6.9. Marking An Exchange As Routed
7. TLS / SSL
7.1. TLS Handshake
8. Configuration
8.1. Fluent Java Routes API
8.2. DiscoveryClient Route Definition Locator
8.2.1. Configuring Predicates and Filters For DiscoveryClient Routes
9. Reactor Netty Access Logs
10. CORS Configuration
11. Actuator API
11.1. Verbose Actuator Format
11.2. Retrieving route filters
11.2.1. Global Filters
11.2.2. Route Filters
11.3. Refreshing the route cache
11.4. Retrieving the routes defined in the gateway
11.5. Retrieving information about a particular route
11.6. Creating and deleting a particular route
11.7. Recap: list of all endpoints
12. Troubleshooting
12.1. Log Levels
12.2. Wiretap
13. Developer Guide
13.1. Writing Custom Route Predicate Factories
13.2. Writing Custom GatewayFilter Factories
13.3. Writing Custom Global Filters
13.4. Writing Custom Route Locators and Writers
14. Building a Simple Gateway Using Spring MVC or Webflux
\ No newline at end of file diff --git a/2.1.x/single/spring-cloud-gateway.html b/2.1.x/single/spring-cloud-gateway.html index 12266e69..39ca6ee8 100644 --- a/2.1.x/single/spring-cloud-gateway.html +++ b/2.1.x/single/spring-cloud-gateway.html @@ -1,6 +1,6 @@ - Spring Cloud Gateway

Spring Cloud Gateway


Table of Contents

1. How to Include Spring Cloud Gateway
2. Glossary
3. How It Works
4. Route Predicate Factories
4.1. After Route Predicate Factory
4.2. Before Route Predicate Factory
4.3. Between Route Predicate Factory
4.4. Cookie Route Predicate Factory
4.5. Header Route Predicate Factory
4.6. Host Route Predicate Factory
4.7. Method Route Predicate Factory
4.8. Path Route Predicate Factory
4.9. Query Route Predicate Factory
4.10. RemoteAddr Route Predicate Factory
4.10.1. Modifying the way remote addresses are resolved
5. GatewayFilter Factories
5.1. AddRequestHeader GatewayFilter Factory
5.2. AddRequestParameter GatewayFilter Factory
5.3. AddResponseHeader GatewayFilter Factory
5.4. DedupeResponseHeader GatewayFilter Factory
5.5. Hystrix GatewayFilter Factory
5.6. FallbackHeaders GatewayFilter Factory
5.7. PrefixPath GatewayFilter Factory
5.8. PreserveHostHeader GatewayFilter Factory
5.9. RequestRateLimiter GatewayFilter Factory
5.9.1. Redis RateLimiter
5.10. RedirectTo GatewayFilter Factory
5.11. RemoveHopByHopHeadersFilter GatewayFilter Factory
5.12. RemoveRequestHeader GatewayFilter Factory
5.13. RemoveResponseHeader GatewayFilter Factory
5.14. RewritePath GatewayFilter Factory
5.15. RewriteResponseHeader GatewayFilter Factory
5.16. SaveSession GatewayFilter Factory
5.17. SecureHeaders GatewayFilter Factory
5.18. SetPath GatewayFilter Factory
5.19. SetRequestHeader GatewayFilter Factory
5.20. SetResponseHeader GatewayFilter Factory
5.21. SetStatus GatewayFilter Factory
5.22. StripPrefix GatewayFilter Factory
5.23. Retry GatewayFilter Factory
5.24. RequestSize GatewayFilter Factory
5.25. Modify Request Body GatewayFilter Factory
5.26. Modify Response Body GatewayFilter Factory
5.27. Default Filters
6. Global Filters
6.1. Combined Global Filter and GatewayFilter Ordering
6.2. Forward Routing Filter
6.3. LoadBalancerClient Filter
6.4. Netty Routing Filter
6.5. Netty Write Response Filter
6.6. RouteToRequestUrl Filter
6.7. Websocket Routing Filter
6.8. Gateway Metrics Filter
6.9. Marking An Exchange As Routed
7. TLS / SSL
7.1. TLS Handshake
8. Configuration
8.1. Fluent Java Routes API
8.2. DiscoveryClient Route Definition Locator
8.2.1. Configuring Predicates and Filters For DiscoveryClient Routes
9. Reactor Netty Access Logs
10. CORS Configuration
11. Actuator API
11.1. Verbose Actuator Format
11.2. Retrieving route filters
11.2.1. Global Filters
11.2.2. Route Filters
11.3. Refreshing the route cache
11.4. Retrieving the routes defined in the gateway
11.5. Retrieving information about a particular route
11.6. Creating and deleting a particular route
11.7. Recap: list of all endpoints
12. Troubleshooting
12.1. Log Levels
12.2. Wiretap
13. Developer Guide
13.1. Writing Custom Route Predicate Factories
13.2. Writing Custom GatewayFilter Factories
13.3. Writing Custom Global Filters
13.4. Writing Custom Route Locators and Writers
14. Building a Simple Gateway Using Spring MVC or Webflux

2.1.3.BUILD-SNAPSHOT

This project provides an API Gateway built on top of the Spring Ecosystem, including: Spring 5, Spring Boot 2 and Project Reactor. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.

1. How to Include Spring Cloud Gateway

To include Spring Cloud Gateway in your project use the starter with group org.springframework.cloud + Spring Cloud Gateway

Spring Cloud Gateway


Table of Contents

1. How to Include Spring Cloud Gateway
2. Glossary
3. How It Works
4. Route Predicate Factories
4.1. After Route Predicate Factory
4.2. Before Route Predicate Factory
4.3. Between Route Predicate Factory
4.4. Cookie Route Predicate Factory
4.5. Header Route Predicate Factory
4.6. Host Route Predicate Factory
4.7. Method Route Predicate Factory
4.8. Path Route Predicate Factory
4.9. Query Route Predicate Factory
4.10. RemoteAddr Route Predicate Factory
4.10.1. Modifying the way remote addresses are resolved
5. GatewayFilter Factories
5.1. AddRequestHeader GatewayFilter Factory
5.2. AddRequestParameter GatewayFilter Factory
5.3. AddResponseHeader GatewayFilter Factory
5.4. DedupeResponseHeader GatewayFilter Factory
5.5. Hystrix GatewayFilter Factory
5.6. FallbackHeaders GatewayFilter Factory
5.7. PrefixPath GatewayFilter Factory
5.8. PreserveHostHeader GatewayFilter Factory
5.9. RequestRateLimiter GatewayFilter Factory
5.9.1. Redis RateLimiter
5.10. RedirectTo GatewayFilter Factory
5.11. RemoveHopByHopHeadersFilter GatewayFilter Factory
5.12. RemoveRequestHeader GatewayFilter Factory
5.13. RemoveResponseHeader GatewayFilter Factory
5.14. RewritePath GatewayFilter Factory
5.15. RewriteLocationResponseHeader GatewayFilter Factory
5.16. RewriteResponseHeader GatewayFilter Factory
5.17. SaveSession GatewayFilter Factory
5.18. SecureHeaders GatewayFilter Factory
5.19. SetPath GatewayFilter Factory
5.20. SetRequestHeader GatewayFilter Factory
5.21. SetResponseHeader GatewayFilter Factory
5.22. SetStatus GatewayFilter Factory
5.23. StripPrefix GatewayFilter Factory
5.24. Retry GatewayFilter Factory
5.25. RequestSize GatewayFilter Factory
5.26. Modify Request Body GatewayFilter Factory
5.27. Modify Response Body GatewayFilter Factory
5.28. Default Filters
6. Global Filters
6.1. Combined Global Filter and GatewayFilter Ordering
6.2. Forward Routing Filter
6.3. LoadBalancerClient Filter
6.4. Netty Routing Filter
6.5. Netty Write Response Filter
6.6. RouteToRequestUrl Filter
6.7. Websocket Routing Filter
6.8. Gateway Metrics Filter
6.9. Marking An Exchange As Routed
7. TLS / SSL
7.1. TLS Handshake
8. Configuration
8.1. Fluent Java Routes API
8.2. DiscoveryClient Route Definition Locator
8.2.1. Configuring Predicates and Filters For DiscoveryClient Routes
9. Reactor Netty Access Logs
10. CORS Configuration
11. Actuator API
11.1. Verbose Actuator Format
11.2. Retrieving route filters
11.2.1. Global Filters
11.2.2. Route Filters
11.3. Refreshing the route cache
11.4. Retrieving the routes defined in the gateway
11.5. Retrieving information about a particular route
11.6. Creating and deleting a particular route
11.7. Recap: list of all endpoints
12. Troubleshooting
12.1. Log Levels
12.2. Wiretap
13. Developer Guide
13.1. Writing Custom Route Predicate Factories
13.2. Writing Custom GatewayFilter Factories
13.3. Writing Custom Global Filters
13.4. Writing Custom Route Locators and Writers
14. Building a Simple Gateway Using Spring MVC or Webflux

2.1.3.BUILD-SNAPSHOT

This project provides an API Gateway built on top of the Spring Ecosystem, including: Spring 5, Spring Boot 2 and Project Reactor. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.

1. How to Include Spring Cloud Gateway

To include Spring Cloud Gateway in your project use the starter with group org.springframework.cloud and artifact id spring-cloud-starter-gateway. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

If you include the starter, but, for some reason, you do not want the gateway to be enabled, set spring.cloud.gateway.enabled=false.

[Important]Important

Spring Cloud Gateway is built upon Spring Boot 2.x, Spring WebFlux, @@ -365,7 +365,16 @@ and have it applied to all routes.

- Path=/foo/** filters: - RewritePath=/foo/(?<segment>.*), /$\{segment}

-

For a request path of /foo/bar, this will set the path to /bar before making the downstream request. Notice the $\ which is replaced with $ because of the YAML spec.

5.15 RewriteResponseHeader GatewayFilter Factory

The RewriteResponseHeader GatewayFilter Factory takes name, regexp, and replacement parameters. It uses Java regular expressions for a flexible way to rewrite the response header value.

application.yml.  +

For a request path of /foo/bar, this will set the path to /bar before making the downstream request. Notice the $\ which is replaced with $ because of the YAML spec.

5.15 RewriteLocationResponseHeader GatewayFilter Factory

The RewriteLocationResponseHeader GatewayFilter Factory modifies the value of Location response header, usually to get rid of backend specific details. It takes stripVersionMode, locationHeaderName, hostValue, and protocolsRegex parameters.

application.yml.  +

spring:
+  cloud:
+    gateway:
+      routes:
+      - id: rewritelocationresponseheader_route
+        uri: http://example.org
+        filters:
+        - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, ,

+

For example, for a request POST https://api.example.com/some/object/name, Location response header value https://object-service.prod.example.net/v2/some/object/id will be rewritten as https://api.example.com/some/object/id.

Parameter stripVersionMode has the following possible values: NEVER_STRIP, AS_IN_REQUEST (default), ALWAYS_STRIP.

  • NEVER_STRIP - Version will not be stripped, even if the original request path contains no version
  • AS_IN_REQUEST - Version will be stripped only if the original request path contains no version
  • ALWAYS_STRIP - Version will be stripped, even if the original request path contains version

Parameter hostValue, if provided, will be used to replace the host:port portion of the response Location header. If not provided, the value of the Host request header will be used.

Parameter protocolsRegex must be a valid regex String, against which the protocol name will be matched. If not matched, the filter will do nothing. Default is http|https|ftp|ftps.

5.16 RewriteResponseHeader GatewayFilter Factory

The RewriteResponseHeader GatewayFilter Factory takes name, regexp, and replacement parameters. It uses Java regular expressions for a flexible way to rewrite the response header value.

application.yml. 

spring:
   cloud:
     gateway:
@@ -374,7 +383,7 @@ and have it applied to all routes.

uri: https://example.org filters: - RewriteResponseHeader=X-Response-Foo, , password=[^&]+, password=***

-

For a header value of /42?user=ford&password=omg!what&flag=true, it will be set to /42?user=ford&password=***&flag=true after making the downstream request. Please use $\ to mean $ because of the YAML spec.

5.16 SaveSession GatewayFilter Factory

The SaveSession GatewayFilter Factory forces a WebSession::save operation before forwarding the call downstream. This is of particular use when +

For a header value of /42?user=ford&password=omg!what&flag=true, it will be set to /42?user=ford&password=***&flag=true after making the downstream request. Please use $\ to mean $ because of the YAML spec.

5.17 SaveSession GatewayFilter Factory

The SaveSession GatewayFilter Factory forces a WebSession::save operation before forwarding the call downstream. This is of particular use when using something like Spring Session with a lazy data store and need to ensure the session state has been saved before making the forwarded call.

application.yml. 

spring:
   cloud:
@@ -386,7 +395,7 @@ using something like         - Path=/foo/**
         filters:
         - SaveSession

-

If you are integrating Spring Security with Spring Session, and want to ensure security details have been forwarded to the remote process, this is critical.

5.17 SecureHeaders GatewayFilter Factory

The SecureHeaders GatewayFilter Factory adds a number of headers to the response at the recommendation from this blog post.

The following headers are added (allong with default values):

  • X-Xss-Protection:1; mode=block
  • Strict-Transport-Security:max-age=631138519
  • X-Frame-Options:DENY
  • X-Content-Type-Options:nosniff
  • Referrer-Policy:no-referrer
  • 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'
  • X-Download-Options:noopen
  • X-Permitted-Cross-Domain-Policies:none

To change the default values set the appropriate property in the spring.cloud.gateway.filter.secure-headers namespace:

Property to change:

  • xss-protection-header
  • strict-transport-security
  • frame-options
  • content-type-options
  • referrer-policy
  • content-security-policy
  • download-options
  • permitted-cross-domain-policies

To disable the default values set the property spring.cloud.gateway.filter.secure-headers.disable with comma separated values.

Example: spring.cloud.gateway.filter.secure-headers.disable=frame-options,download-options

5.18 SetPath GatewayFilter Factory

The SetPath GatewayFilter Factory takes a path template parameter. It offers a simple way to manipulate the request path by allowing templated segments of the path. This uses the uri templates from Spring Framework. Multiple matching segments are allowed.

application.yml.  +

If you are integrating Spring Security with Spring Session, and want to ensure security details have been forwarded to the remote process, this is critical.

5.18 SecureHeaders GatewayFilter Factory

The SecureHeaders GatewayFilter Factory adds a number of headers to the response at the recommendation from this blog post.

The following headers are added (allong with default values):

  • X-Xss-Protection:1; mode=block
  • Strict-Transport-Security:max-age=631138519
  • X-Frame-Options:DENY
  • X-Content-Type-Options:nosniff
  • Referrer-Policy:no-referrer
  • 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'
  • X-Download-Options:noopen
  • X-Permitted-Cross-Domain-Policies:none

To change the default values set the appropriate property in the spring.cloud.gateway.filter.secure-headers namespace:

Property to change:

  • xss-protection-header
  • strict-transport-security
  • frame-options
  • content-type-options
  • referrer-policy
  • content-security-policy
  • download-options
  • permitted-cross-domain-policies

To disable the default values set the property spring.cloud.gateway.filter.secure-headers.disable with comma separated values.

Example: spring.cloud.gateway.filter.secure-headers.disable=frame-options,download-options

5.19 SetPath GatewayFilter Factory

The SetPath GatewayFilter Factory takes a path template parameter. It offers a simple way to manipulate the request path by allowing templated segments of the path. This uses the uri templates from Spring Framework. Multiple matching segments are allowed.

application.yml. 

spring:
   cloud:
     gateway:
@@ -397,7 +406,7 @@ using something like         - Path=/foo/{segment}
         filters:
         - SetPath=/{segment}

-

For a request path of /foo/bar, this will set the path to /bar before making the downstream request.

5.19 SetRequestHeader GatewayFilter Factory

The SetRequestHeader GatewayFilter Factory takes name and value parameters.

application.yml.  +

For a request path of /foo/bar, this will set the path to /bar before making the downstream request.

5.20 SetRequestHeader GatewayFilter Factory

The SetRequestHeader GatewayFilter Factory takes name and value parameters.

application.yml. 

spring:
   cloud:
     gateway:
@@ -417,7 +426,7 @@ using something like         - Host: {segment}.myhost.org
         filters:
         - SetRequestHeader=foo, bar-{segment}

-

5.20 SetResponseHeader GatewayFilter Factory

The SetResponseHeader GatewayFilter Factory takes name and value parameters.

application.yml.  +

5.21 SetResponseHeader GatewayFilter Factory

The SetResponseHeader GatewayFilter Factory takes name and value parameters.

application.yml. 

spring:
   cloud:
     gateway:
@@ -437,7 +446,7 @@ using something like         - Host: {segment}.myhost.org
         filters:
         - SetResponseHeader=foo, bar-{segment}

-

5.21 SetStatus GatewayFilter Factory

The SetStatus GatewayFilter Factory takes a single status parameter. It must be a valid Spring HttpStatus. It may be the integer value 404 or the string representation of the enumeration NOT_FOUND.

application.yml.  +

5.22 SetStatus GatewayFilter Factory

The SetStatus GatewayFilter Factory takes a single status parameter. It must be a valid Spring HttpStatus. It may be the integer value 404 or the string representation of the enumeration NOT_FOUND.

application.yml. 

spring:
   cloud:
     gateway:
@@ -450,7 +459,7 @@ using something like         uri: https://example.org
         filters:
         - SetStatus=401

-

In either case, the HTTP status of the response will be set to 401.

5.22 StripPrefix GatewayFilter Factory

The StripPrefix GatewayFilter Factory takes one paramter, parts. The parts parameter indicated the number of parts in the path to strip from the request before sending it downstream.

application.yml.  +

In either case, the HTTP status of the response will be set to 401.

5.23 StripPrefix GatewayFilter Factory

The StripPrefix GatewayFilter Factory takes one paramter, parts. The parts parameter indicated the number of parts in the path to strip from the request before sending it downstream.

application.yml. 

spring:
   cloud:
     gateway:
@@ -461,7 +470,7 @@ using something like         - Path=/name/**
         filters:
         - StripPrefix=2

-

When a request is made through the gateway to /name/bar/foo the request made to nameservice will look like http://nameservice/foo.

5.23 Retry GatewayFilter Factory

The Retry GatewayFilter Factory takes retries, statuses, methods, and series as parameters.

  • retries: the number of retries that should be attempted
  • statuses: the HTTP status codes that should be retried, represented using org.springframework.http.HttpStatus
  • methods: the HTTP methods that should be retried, represented using org.springframework.http.HttpMethod
  • series: the series of status codes to be retried, represented using org.springframework.http.HttpStatus.Series

application.yml.  +

When a request is made through the gateway to /name/bar/foo the request made to nameservice will look like http://nameservice/foo.

5.24 Retry GatewayFilter Factory

The Retry GatewayFilter Factory takes retries, statuses, methods, and series as parameters.

  • retries: the number of retries that should be attempted
  • statuses: the HTTP status codes that should be retried, represented using org.springframework.http.HttpStatus
  • methods: the HTTP methods that should be retried, represented using org.springframework.http.HttpMethod
  • series: the series of status codes to be retried, represented using org.springframework.http.HttpStatus.Series

application.yml. 

spring:
   cloud:
     gateway:
@@ -475,7 +484,7 @@ using something like           args:
             retries: 3
             statuses: BAD_GATEWAY

-

[Note]Note

The retry filter does not currently support retrying with a body (e.g. for POST or PUT requests with a body).

[Note]Note

When using the retry filter with a forward: prefixed URL, the target endpoint should be written carefully so that in case of an error it does not do anything that could result in a response being sent to the client and committed. For example, if the target endpoint is an annotated controller, the target controller method should not return ResponseEntity with an error status code. Instead it should throw an Exception, or signal an error, e.g. via a Mono.error(ex) return value, which the retry filter can be configured to handle by retrying.

5.24 RequestSize GatewayFilter Factory

The RequestSize GatewayFilter Factory can restrict a request from reaching the downstream service , when the request size is greater than the permissible limit. The filter takes RequestSize as parameter which is the permissible size limit of the request defined in bytes.

application.yml.  +

[Note]Note

The retry filter does not currently support retrying with a body (e.g. for POST or PUT requests with a body).

[Note]Note

When using the retry filter with a forward: prefixed URL, the target endpoint should be written carefully so that in case of an error it does not do anything that could result in a response being sent to the client and committed. For example, if the target endpoint is an annotated controller, the target controller method should not return ResponseEntity with an error status code. Instead it should throw an Exception, or signal an error, e.g. via a Mono.error(ex) return value, which the retry filter can be configured to handle by retrying.

5.25 RequestSize GatewayFilter Factory

The RequestSize GatewayFilter Factory can restrict a request from reaching the downstream service , when the request size is greater than the permissible limit. The filter takes RequestSize as parameter which is the permissible size limit of the request defined in bytes.

application.yml. 

spring:
   cloud:
     gateway:
@@ -488,7 +497,7 @@ using something like       - name: RequestSize
         args:
           maxSize: 5000000

-

The RequestSize GatewayFilter Factory set the response status as 413 Payload Too Large with a additional header errorMessage when the Request is rejected due to size. Following is an example of such an errorMessage .

errorMessage : Request size is larger than permissible limit. Request size is 6.0 MB where permissible limit is 5.0 MB

[Note]Note

The default Request size will be set to 5 MB if not provided as filter argument in route definition.

5.25 Modify Request Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the request body before it is sent downstream by the Gateway.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
+

The RequestSize GatewayFilter Factory set the response status as 413 Payload Too Large with a additional header errorMessage when the Request is rejected due to size. Following is an example of such an errorMessage .

errorMessage : Request size is larger than permissible limit. Request size is 6.0 MB where permissible limit is 5.0 MB

[Note]Note

The default Request size will be set to 5 MB if not provided as filter argument in route definition.

5.26 Modify Request Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the request body before it is sent downstream by the Gateway.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
 public RouteLocator routes(RouteLocatorBuilder builder) {
     return builder.routes()
         .route("rewrite_request_obj", r -> r.host("*.rewriterequestobj.org")
@@ -514,7 +523,7 @@ using something like public void setMessage(String message) {
         this.message = message;
     }
-}

5.26 Modify Response Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the response body before it is sent back to the Client.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
+}

5.27 Modify Response Body GatewayFilter Factory

This filter is considered BETA and the API may change in the future

This filter can be used to modify the response body before it is sent back to the Client.

[Note]Note

This filter can only be configured using the Java DSL

@Bean
 public RouteLocator routes(RouteLocatorBuilder builder) {
     return builder.routes()
         .route("rewrite_response_upper", r -> r.host("*.rewriteresponseupper.org")
@@ -522,7 +531,7 @@ using something like class, String.class,
         		    (exchange, s) -> Mono.just(s.toUpperCase()))).uri(uri)
         .build();
-}

5.27 Default Filters

If you would like to add a filter and apply it to all routes you can use spring.cloud.gateway.default-filters. +}

5.28 Default Filters

If you would like to add a filter and apply it to all routes you can use spring.cloud.gateway.default-filters. This property takes a list of filters

application.yml. 

spring:
   cloud:
diff --git a/2.1.x/spring-cloud-gateway.xml b/2.1.x/spring-cloud-gateway.xml
index c73f0eea..7425685e 100644
--- a/2.1.x/spring-cloud-gateway.xml
+++ b/2.1.x/spring-cloud-gateway.xml
@@ -808,6 +808,38 @@ and have it applied to all routes.
 
 For a request path of /foo/bar, this will set the path to /bar before making the downstream request. Notice the $\ which is replaced with $ because of the YAML spec.
 
+
+RewriteLocationResponseHeader GatewayFilter Factory +The RewriteLocationResponseHeader GatewayFilter Factory modifies the value of Location response header, usually to get rid of backend specific details. It takes stripVersionMode, locationHeaderName, hostValue, and protocolsRegex parameters. + +application.yml + +spring: + cloud: + gateway: + routes: + - id: rewritelocationresponseheader_route + uri: http://example.org + filters: + - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, , + + +For example, for a request POST https://api.example.com/some/object/name, Location response header value https://object-service.prod.example.net/v2/some/object/id will be rewritten as https://api.example.com/some/object/id. +Parameter stripVersionMode has the following possible values: NEVER_STRIP, AS_IN_REQUEST (default), ALWAYS_STRIP. + + +NEVER_STRIP - Version will not be stripped, even if the original request path contains no version + + +AS_IN_REQUEST - Version will be stripped only if the original request path contains no version + + +ALWAYS_STRIP - Version will be stripped, even if the original request path contains version + + +Parameter hostValue, if provided, will be used to replace the host:port portion of the response Location header. If not provided, the value of the Host request header will be used. +Parameter protocolsRegex must be a valid regex String, against which the protocol name will be matched. If not matched, the filter will do nothing. Default is http|https|ftp|ftps. +
RewriteResponseHeader GatewayFilter Factory The RewriteResponseHeader GatewayFilter Factory takes name, regexp, and replacement parameters. It uses Java regular expressions for a flexible way to rewrite the response header value.