diff --git a/2.0.x/multi/multi__configuration.html b/2.0.x/multi/multi__configuration.html index 96668c2e..1ffb52ce 100644 --- a/2.0.x/multi/multi__configuration.html +++ b/2.0.x/multi/multi__configuration.html @@ -21,9 +21,9 @@ filters: - SetStatus=401

For some usages of the gateway, properties will be adequate, but some production use cases will benefit from loading configuration from an external source, such as a database. Future milestone versions will have RouteDefinitionLocator implementations based off of Spring Data Repositories such as: Redis, MongoDB and Cassandra.

7.1 Fluent Java Routes API

To allow for simple configuration in Java, there is a fluent API defined in the Routes class.

Config.java.  -

// static imports from WebFilterFactories and RoutePredicates
+

// static imports from GatewayFilters and RoutePredicates
 @Bean
-public RouteLocator customRouteLocator(ThrottleWebFilterFactory throttle) {
+public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) {
     return Routes.locator()
             .route("test")
                 .uri("http://httpbin.org:80")
diff --git a/2.0.x/multi/multi__developer_guide.html b/2.0.x/multi/multi__developer_guide.html
index 2bd8f340..6d22dbe6 100644
--- a/2.0.x/multi/multi__developer_guide.html
+++ b/2.0.x/multi/multi__developer_guide.html
@@ -1,3 +1,3 @@
 
       
-   9. Developer Guide

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom WebFilter Factories

TODO: document writing Custom WebFilter Factories

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

\ No newline at end of file + 9. Developer Guide

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom GatewayFilter Factories

TODO: document writing Custom GatewayFilter Factories

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

\ No newline at end of file diff --git a/2.0.x/multi/multi__global_filters.html b/2.0.x/multi/multi__global_filters.html index 2c8f929c..de711c23 100644 --- a/2.0.x/multi/multi__global_filters.html +++ b/2.0.x/multi/multi__global_filters.html @@ -1,3 +1,3 @@ - 6. Global Filters

6. Global Filters

The GlobalFilter interface has the same signature as WebFilter. These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones).

6.1 Combined Global Filter and WebFilter Ordering

TODO: document ordering

6.2 Forward Routing Filter

The ForwardRoutingFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a forward scheme (ie forward:///localendpoint), it will use the Spring DispatcherHandler to handler the request. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.3 LoadBalancerClient Filter

The LoadBalancerClientFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a lb scheme (ie lb://myservice), it will use the Spring Cloud LoadBalancerClient to resolve the name (myservice in the previous example) to an actual host and port and replace the URI in the same attribute. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.4 Netty Routing Filter

The Netty Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a http or https scheme. It uses the Netty HttpClient to make the downstream proxy request. The response is put in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute for use in a later filter. (There is an experimental WebClientHttpRoutingFilter that performs the same function, but does not require netty)

6.5 Netty Write Response Filter

The NettyWriteResponseFilter runs if there is a Netty HttpClientResponse in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute. It is run after all other filters have completed and writes the proxy response back to the gateway client response. (There is an experimental WebClientWriteResponseFilter that performs the same function, but does not require netty)

6.6 RouteToRequestUrl Filter

The RouteToRequestUrlFilter runs if there is a Route object in the ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR exchange attribute. It creates a new URI, based off of the request URI, but updated with the URI attribute of the Route object. The new URI is placed in the `ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute`.

6.7 Websocket Routing Filter

The Websocket Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a ws or wss scheme. It uses the Spring Web Socket infrastructure to forward the Websocket request downstream.

\ No newline at end of file + 6. Global Filters

6. Global Filters

The GlobalFilter interface has the same signature as GatewayFilter. These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones).

6.1 Combined Global Filter and GatewayFilter Ordering

TODO: document ordering

6.2 Forward Routing Filter

The ForwardRoutingFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a forward scheme (ie forward:///localendpoint), it will use the Spring DispatcherHandler to handler the request. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.3 LoadBalancerClient Filter

The LoadBalancerClientFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a lb scheme (ie lb://myservice), it will use the Spring Cloud LoadBalancerClient to resolve the name (myservice in the previous example) to an actual host and port and replace the URI in the same attribute. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.4 Netty Routing Filter

The Netty Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a http or https scheme. It uses the Netty HttpClient to make the downstream proxy request. The response is put in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute for use in a later filter. (There is an experimental WebClientHttpRoutingFilter that performs the same function, but does not require netty)

6.5 Netty Write Response Filter

The NettyWriteResponseFilter runs if there is a Netty HttpClientResponse in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute. It is run after all other filters have completed and writes the proxy response back to the gateway client response. (There is an experimental WebClientWriteResponseFilter that performs the same function, but does not require netty)

6.6 RouteToRequestUrl Filter

The RouteToRequestUrlFilter runs if there is a Route object in the ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR exchange attribute. It creates a new URI, based off of the request URI, but updated with the URI attribute of the Route object. The new URI is placed in the `ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute`.

6.7 Websocket Routing Filter

The Websocket Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a ws or wss scheme. It uses the Spring Web Socket infrastructure to forward the Websocket request downstream.

\ No newline at end of file diff --git a/2.0.x/multi/multi__glossary.html b/2.0.x/multi/multi__glossary.html index 1a6b1e4c..b2452c6f 100644 --- a/2.0.x/multi/multi__glossary.html +++ b/2.0.x/multi/multi__glossary.html @@ -1,3 +1,3 @@ - 2. Glossary

2. Glossary

  • Route: Route the basic building block of the gateway. It is defined by an ID, a destination URI, a collection of predicates and a collection of filters. A route is matched if aggregate predicate is true.
  • Predicate: This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This allows developers to match on anything from the HTTP request, such as headers or parameters.
  • Filter: These are instances Spring Framework WebFilter constructed in with a specific factory. Here, requests and responses can be modified before or after sending the downstream request.
\ No newline at end of file + 2. Glossary

2. Glossary

  • Route: Route the basic building block of the gateway. It is defined by an ID, a destination URI, a collection of predicates and a collection of filters. A route is matched if aggregate predicate is true.
  • Predicate: This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This allows developers to match on anything from the HTTP request, such as headers or parameters.
  • Filter: These are instances Spring Framework GatewayFilter constructed in with a specific factory. Here, requests and responses can be modified before or after sending the downstream request.
\ No newline at end of file diff --git a/2.0.x/multi/multi_gateway-request-predicates-factories.html b/2.0.x/multi/multi_gateway-request-predicates-factories.html index 4c426033..7a59d002 100644 --- a/2.0.x/multi/multi_gateway-request-predicates-factories.html +++ b/2.0.x/multi/multi_gateway-request-predicates-factories.html @@ -1,6 +1,6 @@ - 4. Route Predicate Factories

4. Route Predicate Factories

Spring Cloud Gateway matches routes as part of the Spring WebFlux HandlerMapping infrastructure. Spring Cloud Gateway includes many built-in Route Predicate Factories. All of these predicates match on different attributes of the HTTP request. Multiple Route Predicate Factories can be combined and are combined via logical and.

4.1 After Route Predicate Factory

The After Route Predicate Factory takes one parameter, a datetime. This predicate matches requests that happen after the current datetime.

application.yml.  + 4. Route Predicate Factories

4. Route Predicate Factories

Spring Cloud Gateway matches routes as part of the Spring WebFlux HandlerMapping infrastructure. Spring Cloud Gateway includes many built-in Route Predicate Factories. All of these predicates match on different attributes of the HTTP request. Multiple Route Predicate Factories can be combined and are combined via logical and.

4.1 After Route Predicate Factory

The After Route Predicate Factory takes one parameter, a datetime. This predicate matches requests that happen after the current datetime.

application.yml. 

spring:
   cloud:
     gateway:
@@ -80,7 +80,7 @@
         uri: http://example.org
         predicates:
         - Path=/foo/{segment}

-

This route would match if the request path was, for example: /foo/1 or /foo/bar.

This predicate extracts the URI template variables (like segment defined in the example above) as a map of names and values and places it in the ServerWebExchange.getAttributes() with a key defined in PathRoutePredicate.URL_PREDICATE_VARS_ATTR. Those values are then available for use by WebFilter Factories

4.9 Query Route Predicate Factory

The Query Route Predicate Factory takes two parameters: a required param and an optional regexp.

application.yml.  +

This route would match if the request path was, for example: /foo/1 or /foo/bar.

This predicate extracts the URI template variables (like segment defined in the example above) as a map of names and values and places it in the ServerWebExchange.getAttributes() with a key defined in PathRoutePredicate.URL_PREDICATE_VARS_ATTR. Those values are then available for use by GatewayFilter Factories

4.9 Query Route Predicate Factory

The Query Route Predicate Factory takes two parameters: a required param and an optional regexp.

application.yml. 

spring:
   cloud:
     gateway:
@@ -110,4 +110,4 @@
         uri: http://example.org
         predicates:
         - RemoteAddr=192.168.1.1/24

-

This route would match if the remote address of the request was, for example, 192.168.1.10.

\ No newline at end of file +

This route would match if the remote address of the request was, for example, 192.168.1.10.

\ No newline at end of file diff --git a/2.0.x/multi/multi_gateway-route-filters.html b/2.0.x/multi/multi_gateway-route-filters.html index baf17877..78ae6e4c 100644 --- a/2.0.x/multi/multi_gateway-route-filters.html +++ b/2.0.x/multi/multi_gateway-route-filters.html @@ -1,6 +1,6 @@ - 5. WebFilter Factories

5. WebFilter Factories

Route filters allow the modification of the incoming HTTP request or outgoing HTTP response in some manner. Route filters are scoped to a particular route. Spring Cloud Gateway includes many built-in WebFilter Factories.

5.1 AddRequestHeader WebFilter Factory

The AddRequestHeader WebFilter Factory takes a name and value parameter.

application.yml.  + 5. GatewayFilter Factories

5. GatewayFilter Factories

Route filters allow the modification of the incoming HTTP request or outgoing HTTP response in some manner. Route filters are scoped to a particular route. Spring Cloud Gateway includes many built-in GatewayFilter Factories.

5.1 AddRequestHeader GatewayFilter Factory

The AddRequestHeader GatewayFilter Factory takes a name and value parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -10,7 +10,7 @@
         uri: http://example.org
         filters:
         - AddRequestHeader=X-Request-Foo, Bar

-

This will add X-Request-Foo:Bar header to the downstream request’s headers for all matching requests.

5.2 AddRequestParameter WebFilter Factory

The AddRequestParameter WebFilter Factory takes a name and value parameter.

application.yml.  +

This will add X-Request-Foo:Bar header to the downstream request’s headers for all matching requests.

5.2 AddRequestParameter GatewayFilter Factory

The AddRequestParameter GatewayFilter Factory takes a name and value parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -20,7 +20,7 @@
         uri: http://example.org
         filters:
         - AddRequestParameter=foo, bar

-

This will add foo=bar to the downstream request’s query string for all matching requests.

5.3 AddResponseHeader WebFilter Factory

The AddResponseHeader WebFilter Factory takes a name and value parameter.

application.yml.  +

This will add foo=bar to the downstream request’s query string for all matching requests.

5.3 AddResponseHeader GatewayFilter Factory

The AddResponseHeader GatewayFilter Factory takes a name and value parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -30,7 +30,7 @@
         uri: http://example.org
         filters:
         - AddResponseHeader=X-Response-Foo, Bar

-

This will add X-Response-Foo:Bar header to the downstream response’s headers for all matching requests.

5.4 Hystrix WebFilter Factory

The Hystrix WebFilter Factory takes a single name parameters, which is the name of the HystrixCommand. (More options might be added in future releases).

application.yml.  +

This will add X-Response-Foo:Bar header to the downstream response’s headers for all matching requests.

5.4 Hystrix GatewayFilter Factory

The Hystrix GatewayFilter Factory takes a single name parameters, which is the name of the HystrixCommand. (More options might be added in future releases).

application.yml. 

spring:
   cloud:
     gateway:
@@ -40,7 +40,7 @@
         uri: http://example.org
         filters:
         - Hystrix=myCommandName

-

This wraps the remaining filters in a HystrixCommand with command name myCommandName.

5.5 PrefixPath WebFilter Factory

The PrefixPath WebFilter Factory takes a single prefix parameter.

application.yml.  +

This wraps the remaining filters in a HystrixCommand with command name myCommandName.

5.5 PrefixPath GatewayFilter Factory

The PrefixPath GatewayFilter Factory takes a single prefix parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -50,7 +50,7 @@
         uri: http://example.org
         filters:
         - PrefixPath=/mypath

-

This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.

5.6 RequestRateLimiter WebFilter Factory

The RequestRateLimiter WebFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.

replenishRate is how many requests per second do you want a user to be allowed to do.

burstCapacity TODO: document burst capacity

keyResolverName is the name of a bean that implements the KeyResolver interface.

KeyResolver.java.  +

This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.

5.6 RequestRateLimiter GatewayFilter Factory

The RequestRateLimiter GatewayFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.

replenishRate is how many requests per second do you want a user to be allowed to do.

burstCapacity TODO: document burst capacity

keyResolverName is the name of a bean that implements the KeyResolver interface.

KeyResolver.java. 

public interface KeyResolver {
 	Mono<String> resolve(ServerWebExchange exchange);
 }

@@ -69,7 +69,7 @@ KeyResolver userKeyResolver() { return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user")); }

-

This defines a request rate limit of 10 per user. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).

5.7 RedirectTo WebFilter Factory

The RedirectTo WebFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.

application.yml.  +

This defines a request rate limit of 10 per user. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).

5.7 RedirectTo GatewayFilter Factory

The RedirectTo GatewayFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.

application.yml. 

spring:
   cloud:
     gateway:
@@ -79,7 +79,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - RedirectTo=302, http://acme.org

-

This will send a status 302 with a Location:http://acme.org header to perform a redirect.

5.8 RemoveNonProxyHeaders WebFilter Factory

The RemoveNonProxyHeaders WebFilter Factory removes headers from forwarded requests. The default list of headers that is removed comes from the IETF.

The default removed headers are:

To change this, set the spring.cloud.gateway.filter.remove-non-proxy-headers.headers property to the list of header names to remove.

5.9 RemoveRequestHeader WebFilter Factory

The RemoveRequestHeader WebFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml.  +

This will send a status 302 with a Location:http://acme.org header to perform a redirect.

5.8 RemoveNonProxyHeaders GatewayFilter Factory

The RemoveNonProxyHeaders GatewayFilter Factory removes headers from forwarded requests. The default list of headers that is removed comes from the IETF.

The default removed headers are:

To change this, set the spring.cloud.gateway.filter.remove-non-proxy-headers.headers property to the list of header names to remove.

5.9 RemoveRequestHeader GatewayFilter Factory

The RemoveRequestHeader GatewayFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml. 

spring:
   cloud:
     gateway:
@@ -89,7 +89,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - RemoveRequestHeader=X-Request-Foo

-

This will remove the X-Request-Foo header before it is sent downstream.

5.10 RemoveResponseHeader WebFilter Factory

The RemoveResponseHeader WebFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml.  +

This will remove the X-Request-Foo header before it is sent downstream.

5.10 RemoveResponseHeader GatewayFilter Factory

The RemoveResponseHeader GatewayFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml. 

spring:
   cloud:
     gateway:
@@ -99,7 +99,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - RemoveResponseHeader=X-Response-Foo

-

This will remove the X-Response-Foo header from the response before it is returned to the gateway client.

5.11 RewritePath WebFilter Factory

The RewritePath WebFilter Factory takes a path regexp parameter and a replacement parameter. This uses Java regular expressions for a flexible way to rewrite the request path.

application.yml.  +

This will remove the X-Response-Foo header from the response before it is returned to the gateway client.

5.11 RewritePath GatewayFilter Factory

The RewritePath GatewayFilter Factory takes a path regexp parameter and a replacement parameter. This uses Java regular expressions for a flexible way to rewrite the request path.

application.yml. 

spring:
   cloud:
     gateway:
@@ -110,7 +110,7 @@ KeyResolver userKeyResolver() {
         - 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.12 SecureHeaders WebFilter Factory

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

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

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

Property to change:

5.13 SetPath WebFilter Factory

The SetPath WebFilter 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.  +

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.12 SecureHeaders GatewayFilter Factory

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

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

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

Property to change:

5.13 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:
@@ -122,7 +122,7 @@ KeyResolver userKeyResolver() {
         - 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.14 SetResponseHeader WebFilter Factory

The SetResponseHeader WebFilter 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.14 SetResponseHeader GatewayFilter Factory

The SetResponseHeader GatewayFilter Factory takes name and value parameters.

application.yml. 

spring:
   cloud:
     gateway:
@@ -132,7 +132,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - SetResponseHeader=X-Response-Foo, Bar

-

This WebFilter replaces all headers with the given name, rather than adding. So if the downstream server responded with a X-Response-Foo:1234, this would be replaced with X-Response-Foo:Bar, which is what the gateway client would receive.

5.15 SetStatus WebFilter Factory

The SetStatus WebFilter 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.  +

This GatewayFilter replaces all headers with the given name, rather than adding. So if the downstream server responded with a X-Response-Foo:1234, this would be replaced with X-Response-Foo:Bar, which is what the gateway client would receive.

5.15 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:
diff --git a/2.0.x/multi/multi_spring-cloud-gateway.html b/2.0.x/multi/multi_spring-cloud-gateway.html
index f296b41f..325cfd1e 100644
--- a/2.0.x/multi/multi_spring-cloud-gateway.html
+++ b/2.0.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
5. WebFilter Factories
5.1. AddRequestHeader WebFilter Factory
5.2. AddRequestParameter WebFilter Factory
5.3. AddResponseHeader WebFilter Factory
5.4. Hystrix WebFilter Factory
5.5. PrefixPath WebFilter Factory
5.6. RequestRateLimiter WebFilter Factory
5.7. RedirectTo WebFilter Factory
5.8. RemoveNonProxyHeaders WebFilter Factory
5.9. RemoveRequestHeader WebFilter Factory
5.10. RemoveResponseHeader WebFilter Factory
5.11. RewritePath WebFilter Factory
5.12. SecureHeaders WebFilter Factory
5.13. SetPath WebFilter Factory
5.14. SetResponseHeader WebFilter Factory
5.15. SetStatus WebFilter Factory
6. Global Filters
6.1. Combined Global Filter and WebFilter 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
7. Configuration
7.1. Fluent Java Routes API
8. Actuator API
9. Developer Guide
9.1. Writing Custom Route Predicate Factories
9.2. Writing Custom WebFilter Factories
9.3. Writing Custom Global Filters
9.4. Writing Custom Route Locators and Writers
10. Building a Simple Gateway Using Spring MVC
\ 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
5. GatewayFilter Factories
5.1. AddRequestHeader GatewayFilter Factory
5.2. AddRequestParameter GatewayFilter Factory
5.3. AddResponseHeader GatewayFilter Factory
5.4. Hystrix GatewayFilter Factory
5.5. PrefixPath GatewayFilter Factory
5.6. RequestRateLimiter GatewayFilter Factory
5.7. RedirectTo GatewayFilter Factory
5.8. RemoveNonProxyHeaders GatewayFilter Factory
5.9. RemoveRequestHeader GatewayFilter Factory
5.10. RemoveResponseHeader GatewayFilter Factory
5.11. RewritePath GatewayFilter Factory
5.12. SecureHeaders GatewayFilter Factory
5.13. SetPath GatewayFilter Factory
5.14. SetResponseHeader GatewayFilter Factory
5.15. SetStatus GatewayFilter Factory
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
7. Configuration
7.1. Fluent Java Routes API
8. Actuator API
9. Developer Guide
9.1. Writing Custom Route Predicate Factories
9.2. Writing Custom GatewayFilter Factories
9.3. Writing Custom Global Filters
9.4. Writing Custom Route Locators and Writers
10. Building a Simple Gateway Using Spring MVC
\ No newline at end of file diff --git a/2.0.x/single/spring-cloud-gateway.html b/2.0.x/single/spring-cloud-gateway.html index 66015464..e29adfec 100644 --- a/2.0.x/single/spring-cloud-gateway.html +++ b/2.0.x/single/spring-cloud-gateway.html @@ -1,8 +1,8 @@ - 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
5. WebFilter Factories
5.1. AddRequestHeader WebFilter Factory
5.2. AddRequestParameter WebFilter Factory
5.3. AddResponseHeader WebFilter Factory
5.4. Hystrix WebFilter Factory
5.5. PrefixPath WebFilter Factory
5.6. RequestRateLimiter WebFilter Factory
5.7. RedirectTo WebFilter Factory
5.8. RemoveNonProxyHeaders WebFilter Factory
5.9. RemoveRequestHeader WebFilter Factory
5.10. RemoveResponseHeader WebFilter Factory
5.11. RewritePath WebFilter Factory
5.12. SecureHeaders WebFilter Factory
5.13. SetPath WebFilter Factory
5.14. SetResponseHeader WebFilter Factory
5.15. SetStatus WebFilter Factory
6. Global Filters
6.1. Combined Global Filter and WebFilter 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
7. Configuration
7.1. Fluent Java Routes API
8. Actuator API
9. Developer Guide
9.1. Writing Custom Route Predicate Factories
9.2. Writing Custom WebFilter Factories
9.3. Writing Custom Global Filters
9.4. Writing Custom Route Locators and Writers
10. Building a Simple Gateway Using Spring MVC

2.0.0.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
5. GatewayFilter Factories
5.1. AddRequestHeader GatewayFilter Factory
5.2. AddRequestParameter GatewayFilter Factory
5.3. AddResponseHeader GatewayFilter Factory
5.4. Hystrix GatewayFilter Factory
5.5. PrefixPath GatewayFilter Factory
5.6. RequestRateLimiter GatewayFilter Factory
5.7. RedirectTo GatewayFilter Factory
5.8. RemoveNonProxyHeaders GatewayFilter Factory
5.9. RemoveRequestHeader GatewayFilter Factory
5.10. RemoveResponseHeader GatewayFilter Factory
5.11. RewritePath GatewayFilter Factory
5.12. SecureHeaders GatewayFilter Factory
5.13. SetPath GatewayFilter Factory
5.14. SetResponseHeader GatewayFilter Factory
5.15. SetStatus GatewayFilter Factory
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
7. Configuration
7.1. Fluent Java Routes API
8. Actuator API
9. Developer Guide
9.1. Writing Custom Route Predicate Factories
9.2. Writing Custom GatewayFilter Factories
9.3. Writing Custom Global Filters
9.4. Writing Custom Route Locators and Writers
10. Building a Simple Gateway Using Spring MVC

2.0.0.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.

2. Glossary

  • Route: Route the basic building block of the gateway. It is defined by an ID, a destination URI, a collection of predicates and a collection of filters. A route is matched if aggregate predicate is true.
  • Predicate: This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This allows developers to match on anything from the HTTP request, such as headers or parameters.
  • Filter: These are instances Spring Framework WebFilter constructed in with a specific factory. Here, requests and responses can be modified before or after sending the downstream request.

3. How It Works

Spring Cloud Gateway Diagram

Clients make requests to Spring Cloud Gateway. If the Gateway Handler Mapping determines that a request matches a Route, it is sent to the Gateway Web Handler. This handler runs sends the request through a filter chain that is specific to the request. The reason the filters are divided by the dotted line, is that filters may execute logic before the proxy request is sent or after. All "pre" filter logic is executed, then the proxy request is made. After the proxy request is made, the "post" filter logic is executed.

4. Route Predicate Factories

Spring Cloud Gateway matches routes as part of the Spring WebFlux HandlerMapping infrastructure. Spring Cloud Gateway includes many built-in Route Predicate Factories. All of these predicates match on different attributes of the HTTP request. Multiple Route Predicate Factories can be combined and are combined via logical and.

4.1 After Route Predicate Factory

The After Route Predicate Factory takes one parameter, a datetime. This predicate matches requests that happen after the current datetime.

application.yml.  +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.

2. Glossary

  • Route: Route the basic building block of the gateway. It is defined by an ID, a destination URI, a collection of predicates and a collection of filters. A route is matched if aggregate predicate is true.
  • Predicate: This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This allows developers to match on anything from the HTTP request, such as headers or parameters.
  • Filter: These are instances Spring Framework GatewayFilter constructed in with a specific factory. Here, requests and responses can be modified before or after sending the downstream request.

3. How It Works

Spring Cloud Gateway Diagram

Clients make requests to Spring Cloud Gateway. If the Gateway Handler Mapping determines that a request matches a Route, it is sent to the Gateway Web Handler. This handler runs sends the request through a filter chain that is specific to the request. The reason the filters are divided by the dotted line, is that filters may execute logic before the proxy request is sent or after. All "pre" filter logic is executed, then the proxy request is made. After the proxy request is made, the "post" filter logic is executed.

4. Route Predicate Factories

Spring Cloud Gateway matches routes as part of the Spring WebFlux HandlerMapping infrastructure. Spring Cloud Gateway includes many built-in Route Predicate Factories. All of these predicates match on different attributes of the HTTP request. Multiple Route Predicate Factories can be combined and are combined via logical and.

4.1 After Route Predicate Factory

The After Route Predicate Factory takes one parameter, a datetime. This predicate matches requests that happen after the current datetime.

application.yml. 

spring:
   cloud:
     gateway:
@@ -82,7 +82,7 @@ for details on setting up your build system with the current Spring Cloud Releas
         uri: http://example.org
         predicates:
         - Path=/foo/{segment}

-

This route would match if the request path was, for example: /foo/1 or /foo/bar.

This predicate extracts the URI template variables (like segment defined in the example above) as a map of names and values and places it in the ServerWebExchange.getAttributes() with a key defined in PathRoutePredicate.URL_PREDICATE_VARS_ATTR. Those values are then available for use by WebFilter Factories

4.9 Query Route Predicate Factory

The Query Route Predicate Factory takes two parameters: a required param and an optional regexp.

application.yml.  +

This route would match if the request path was, for example: /foo/1 or /foo/bar.

This predicate extracts the URI template variables (like segment defined in the example above) as a map of names and values and places it in the ServerWebExchange.getAttributes() with a key defined in PathRoutePredicate.URL_PREDICATE_VARS_ATTR. Those values are then available for use by GatewayFilter Factories

4.9 Query Route Predicate Factory

The Query Route Predicate Factory takes two parameters: a required param and an optional regexp.

application.yml. 

spring:
   cloud:
     gateway:
@@ -112,7 +112,7 @@ for details on setting up your build system with the current Spring Cloud Releas
         uri: http://example.org
         predicates:
         - RemoteAddr=192.168.1.1/24

-

This route would match if the remote address of the request was, for example, 192.168.1.10.

5. WebFilter Factories

Route filters allow the modification of the incoming HTTP request or outgoing HTTP response in some manner. Route filters are scoped to a particular route. Spring Cloud Gateway includes many built-in WebFilter Factories.

5.1 AddRequestHeader WebFilter Factory

The AddRequestHeader WebFilter Factory takes a name and value parameter.

application.yml.  +

This route would match if the remote address of the request was, for example, 192.168.1.10.

5. GatewayFilter Factories

Route filters allow the modification of the incoming HTTP request or outgoing HTTP response in some manner. Route filters are scoped to a particular route. Spring Cloud Gateway includes many built-in GatewayFilter Factories.

5.1 AddRequestHeader GatewayFilter Factory

The AddRequestHeader GatewayFilter Factory takes a name and value parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -122,7 +122,7 @@ for details on setting up your build system with the current Spring Cloud Releas
         uri: http://example.org
         filters:
         - AddRequestHeader=X-Request-Foo, Bar

-

This will add X-Request-Foo:Bar header to the downstream request’s headers for all matching requests.

5.2 AddRequestParameter WebFilter Factory

The AddRequestParameter WebFilter Factory takes a name and value parameter.

application.yml.  +

This will add X-Request-Foo:Bar header to the downstream request’s headers for all matching requests.

5.2 AddRequestParameter GatewayFilter Factory

The AddRequestParameter GatewayFilter Factory takes a name and value parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -132,7 +132,7 @@ for details on setting up your build system with the current Spring Cloud Releas
         uri: http://example.org
         filters:
         - AddRequestParameter=foo, bar

-

This will add foo=bar to the downstream request’s query string for all matching requests.

5.3 AddResponseHeader WebFilter Factory

The AddResponseHeader WebFilter Factory takes a name and value parameter.

application.yml.  +

This will add foo=bar to the downstream request’s query string for all matching requests.

5.3 AddResponseHeader GatewayFilter Factory

The AddResponseHeader GatewayFilter Factory takes a name and value parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -142,7 +142,7 @@ for details on setting up your build system with the current Spring Cloud Releas
         uri: http://example.org
         filters:
         - AddResponseHeader=X-Response-Foo, Bar

-

This will add X-Response-Foo:Bar header to the downstream response’s headers for all matching requests.

5.4 Hystrix WebFilter Factory

The Hystrix WebFilter Factory takes a single name parameters, which is the name of the HystrixCommand. (More options might be added in future releases).

application.yml.  +

This will add X-Response-Foo:Bar header to the downstream response’s headers for all matching requests.

5.4 Hystrix GatewayFilter Factory

The Hystrix GatewayFilter Factory takes a single name parameters, which is the name of the HystrixCommand. (More options might be added in future releases).

application.yml. 

spring:
   cloud:
     gateway:
@@ -152,7 +152,7 @@ for details on setting up your build system with the current Spring Cloud Releas
         uri: http://example.org
         filters:
         - Hystrix=myCommandName

-

This wraps the remaining filters in a HystrixCommand with command name myCommandName.

5.5 PrefixPath WebFilter Factory

The PrefixPath WebFilter Factory takes a single prefix parameter.

application.yml.  +

This wraps the remaining filters in a HystrixCommand with command name myCommandName.

5.5 PrefixPath GatewayFilter Factory

The PrefixPath GatewayFilter Factory takes a single prefix parameter.

application.yml. 

spring:
   cloud:
     gateway:
@@ -162,7 +162,7 @@ for details on setting up your build system with the current Spring Cloud Releas
         uri: http://example.org
         filters:
         - PrefixPath=/mypath

-

This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.

5.6 RequestRateLimiter WebFilter Factory

The RequestRateLimiter WebFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.

replenishRate is how many requests per second do you want a user to be allowed to do.

burstCapacity TODO: document burst capacity

keyResolverName is the name of a bean that implements the KeyResolver interface.

KeyResolver.java.  +

This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.

5.6 RequestRateLimiter GatewayFilter Factory

The RequestRateLimiter GatewayFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName.

replenishRate is how many requests per second do you want a user to be allowed to do.

burstCapacity TODO: document burst capacity

keyResolverName is the name of a bean that implements the KeyResolver interface.

KeyResolver.java. 

public interface KeyResolver {
 	Mono<String> resolve(ServerWebExchange exchange);
 }

@@ -181,7 +181,7 @@ for details on setting up your build system with the current Spring Cloud Releas KeyResolver userKeyResolver() { return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user")); }

-

This defines a request rate limit of 10 per user. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).

5.7 RedirectTo WebFilter Factory

The RedirectTo WebFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.

application.yml.  +

This defines a request rate limit of 10 per user. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).

5.7 RedirectTo GatewayFilter Factory

The RedirectTo GatewayFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header.

application.yml. 

spring:
   cloud:
     gateway:
@@ -191,7 +191,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - RedirectTo=302, http://acme.org

-

This will send a status 302 with a Location:http://acme.org header to perform a redirect.

5.8 RemoveNonProxyHeaders WebFilter Factory

The RemoveNonProxyHeaders WebFilter Factory removes headers from forwarded requests. The default list of headers that is removed comes from the IETF.

The default removed headers are:

To change this, set the spring.cloud.gateway.filter.remove-non-proxy-headers.headers property to the list of header names to remove.

5.9 RemoveRequestHeader WebFilter Factory

The RemoveRequestHeader WebFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml.  +

This will send a status 302 with a Location:http://acme.org header to perform a redirect.

5.8 RemoveNonProxyHeaders GatewayFilter Factory

The RemoveNonProxyHeaders GatewayFilter Factory removes headers from forwarded requests. The default list of headers that is removed comes from the IETF.

The default removed headers are:

To change this, set the spring.cloud.gateway.filter.remove-non-proxy-headers.headers property to the list of header names to remove.

5.9 RemoveRequestHeader GatewayFilter Factory

The RemoveRequestHeader GatewayFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml. 

spring:
   cloud:
     gateway:
@@ -201,7 +201,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - RemoveRequestHeader=X-Request-Foo

-

This will remove the X-Request-Foo header before it is sent downstream.

5.10 RemoveResponseHeader WebFilter Factory

The RemoveResponseHeader WebFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml.  +

This will remove the X-Request-Foo header before it is sent downstream.

5.10 RemoveResponseHeader GatewayFilter Factory

The RemoveResponseHeader GatewayFilter Factory takes a name parameter. It is the name of the header to be removed.

application.yml. 

spring:
   cloud:
     gateway:
@@ -211,7 +211,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - RemoveResponseHeader=X-Response-Foo

-

This will remove the X-Response-Foo header from the response before it is returned to the gateway client.

5.11 RewritePath WebFilter Factory

The RewritePath WebFilter Factory takes a path regexp parameter and a replacement parameter. This uses Java regular expressions for a flexible way to rewrite the request path.

application.yml.  +

This will remove the X-Response-Foo header from the response before it is returned to the gateway client.

5.11 RewritePath GatewayFilter Factory

The RewritePath GatewayFilter Factory takes a path regexp parameter and a replacement parameter. This uses Java regular expressions for a flexible way to rewrite the request path.

application.yml. 

spring:
   cloud:
     gateway:
@@ -222,7 +222,7 @@ KeyResolver userKeyResolver() {
         - 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.12 SecureHeaders WebFilter Factory

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

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

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

Property to change:

5.13 SetPath WebFilter Factory

The SetPath WebFilter 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.  +

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.12 SecureHeaders GatewayFilter Factory

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

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

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

Property to change:

5.13 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:
@@ -234,7 +234,7 @@ KeyResolver userKeyResolver() {
         - 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.14 SetResponseHeader WebFilter Factory

The SetResponseHeader WebFilter 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.14 SetResponseHeader GatewayFilter Factory

The SetResponseHeader GatewayFilter Factory takes name and value parameters.

application.yml. 

spring:
   cloud:
     gateway:
@@ -244,7 +244,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - SetResponseHeader=X-Response-Foo, Bar

-

This WebFilter replaces all headers with the given name, rather than adding. So if the downstream server responded with a X-Response-Foo:1234, this would be replaced with X-Response-Foo:Bar, which is what the gateway client would receive.

5.15 SetStatus WebFilter Factory

The SetStatus WebFilter 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.  +

This GatewayFilter replaces all headers with the given name, rather than adding. So if the downstream server responded with a X-Response-Foo:1234, this would be replaced with X-Response-Foo:Bar, which is what the gateway client would receive.

5.15 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:
@@ -258,7 +258,7 @@ KeyResolver userKeyResolver() {
         uri: http://example.org
         filters:
         - SetStatus=401

-

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

6. Global Filters

The GlobalFilter interface has the same signature as WebFilter. These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones).

6.1 Combined Global Filter and WebFilter Ordering

TODO: document ordering

6.2 Forward Routing Filter

The ForwardRoutingFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a forward scheme (ie forward:///localendpoint), it will use the Spring DispatcherHandler to handler the request. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.3 LoadBalancerClient Filter

The LoadBalancerClientFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a lb scheme (ie lb://myservice), it will use the Spring Cloud LoadBalancerClient to resolve the name (myservice in the previous example) to an actual host and port and replace the URI in the same attribute. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.4 Netty Routing Filter

The Netty Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a http or https scheme. It uses the Netty HttpClient to make the downstream proxy request. The response is put in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute for use in a later filter. (There is an experimental WebClientHttpRoutingFilter that performs the same function, but does not require netty)

6.5 Netty Write Response Filter

The NettyWriteResponseFilter runs if there is a Netty HttpClientResponse in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute. It is run after all other filters have completed and writes the proxy response back to the gateway client response. (There is an experimental WebClientWriteResponseFilter that performs the same function, but does not require netty)

6.6 RouteToRequestUrl Filter

The RouteToRequestUrlFilter runs if there is a Route object in the ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR exchange attribute. It creates a new URI, based off of the request URI, but updated with the URI attribute of the Route object. The new URI is placed in the `ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute`.

6.7 Websocket Routing Filter

The Websocket Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a ws or wss scheme. It uses the Spring Web Socket infrastructure to forward the Websocket request downstream.

7. Configuration

Configuration for Spring Cloud Gateway is driven by a collection of `RouteDefinitionLocator`s.

RouteDefinitionLocator.java.  +

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

6. Global Filters

The GlobalFilter interface has the same signature as GatewayFilter. These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones).

6.1 Combined Global Filter and GatewayFilter Ordering

TODO: document ordering

6.2 Forward Routing Filter

The ForwardRoutingFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a forward scheme (ie forward:///localendpoint), it will use the Spring DispatcherHandler to handler the request. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.3 LoadBalancerClient Filter

The LoadBalancerClientFilter looks for a URI in the exchange attribute ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR. If the url has a lb scheme (ie lb://myservice), it will use the Spring Cloud LoadBalancerClient to resolve the name (myservice in the previous example) to an actual host and port and replace the URI in the same attribute. The unmodified original url is appended to the list in the ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR attribute.

6.4 Netty Routing Filter

The Netty Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a http or https scheme. It uses the Netty HttpClient to make the downstream proxy request. The response is put in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute for use in a later filter. (There is an experimental WebClientHttpRoutingFilter that performs the same function, but does not require netty)

6.5 Netty Write Response Filter

The NettyWriteResponseFilter runs if there is a Netty HttpClientResponse in the ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR exchange attribute. It is run after all other filters have completed and writes the proxy response back to the gateway client response. (There is an experimental WebClientWriteResponseFilter that performs the same function, but does not require netty)

6.6 RouteToRequestUrl Filter

The RouteToRequestUrlFilter runs if there is a Route object in the ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR exchange attribute. It creates a new URI, based off of the request URI, but updated with the URI attribute of the Route object. The new URI is placed in the `ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute`.

6.7 Websocket Routing Filter

The Websocket Routing Filter runs if the url located in the ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR exchange attribute has a ws or wss scheme. It uses the Spring Web Socket infrastructure to forward the Websocket request downstream.

7. Configuration

Configuration for Spring Cloud Gateway is driven by a collection of `RouteDefinitionLocator`s.

RouteDefinitionLocator.java. 

public interface RouteDefinitionLocator {
 	Flux<RouteDefinition> getRouteDefinitions();
 }

@@ -279,9 +279,9 @@ KeyResolver userKeyResolver() { filters: - SetStatus=401

For some usages of the gateway, properties will be adequate, but some production use cases will benefit from loading configuration from an external source, such as a database. Future milestone versions will have RouteDefinitionLocator implementations based off of Spring Data Repositories such as: Redis, MongoDB and Cassandra.

7.1 Fluent Java Routes API

To allow for simple configuration in Java, there is a fluent API defined in the Routes class.

Config.java.  -

// static imports from WebFilterFactories and RoutePredicates
+

// static imports from GatewayFilters and RoutePredicates
 @Bean
-public RouteLocator customRouteLocator(ThrottleWebFilterFactory throttle) {
+public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) {
     return Routes.locator()
             .route("test")
                 .uri("http://httpbin.org:80")
@@ -295,7 +295,7 @@ KeyResolver userKeyResolver() {
                 .and()
             .build();
 }

-

This style also allows for more custom predicate assertions. The predicates defined by RouteDefinitionLocator beans are combined using logical and. By using the fluent Java API, you can use the and(), or() and negate() operators on the Predicate class.

8. Actuator API

TODO: document the /gateway actuator endpoint

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom WebFilter Factories

TODO: document writing Custom WebFilter Factories

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

10. Building a Simple Gateway Using Spring MVC

Spring Cloud Gateway provides a utility object called ProxyExchange which you can use inside a regular Spring MVC handler as a method parameter. It supports basic downstream HTTP exchanges via methods that mirror the HTTP verbs, or forwarding to a local handler via the forward() method.

Example (proxying a request to "/test" downstream to a remote server):

@RestController
+

This style also allows for more custom predicate assertions. The predicates defined by RouteDefinitionLocator beans are combined using logical and. By using the fluent Java API, you can use the and(), or() and negate() operators on the Predicate class.

8. Actuator API

TODO: document the /gateway actuator endpoint

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom GatewayFilter Factories

TODO: document writing Custom GatewayFilter Factories

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

10. Building a Simple Gateway Using Spring MVC

Spring Cloud Gateway provides a utility object called ProxyExchange which you can use inside a regular Spring MVC handler as a method parameter. It supports basic downstream HTTP exchanges via methods that mirror the HTTP verbs, or forwarding to a local handler via the forward() method.

Example (proxying a request to "/test" downstream to a remote server):

@RestController
 @SpringBootApplication
 public class GatewaySampleApplication {
 
diff --git a/2.0.x/spring-cloud-gateway.xml b/2.0.x/spring-cloud-gateway.xml
index 729c97cf..b46df32e 100644
--- a/2.0.x/spring-cloud-gateway.xml
+++ b/2.0.x/spring-cloud-gateway.xml
@@ -4,7 +4,7 @@
 
 
 Spring Cloud Gateway
-2017-10-12
+2017-10-16
 
 
 
@@ -28,7 +28,7 @@ for details on setting up your build system with the current Spring Cloud Releas
 Predicate: This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This allows developers to match on anything from the HTTP request, such as headers or parameters.
 
 
-Filter: These are instances Spring Framework WebFilter constructed in with a specific factory. Here, requests and responses can be modified before or after sending the downstream request.
+Filter: These are instances Spring Framework GatewayFilter constructed in with a specific factory. Here, requests and responses can be modified before or after sending the downstream request.
 
 
 
@@ -198,7 +198,7 @@ for details on setting up your build system with the current Spring Cloud Releas
 
 
 This route would match if the request path was, for example: /foo/1 or /foo/bar.
-This predicate extracts the URI template variables (like segment defined in the example above) as a map of names and values and places it in the ServerWebExchange.getAttributes() with a key defined in PathRoutePredicate.URL_PREDICATE_VARS_ATTR. Those values are then available for use by WebFilter Factories
+This predicate extracts the URI template variables (like segment defined in the example above) as a map of names and values and places it in the ServerWebExchange.getAttributes() with a key defined in PathRoutePredicate.URL_PREDICATE_VARS_ATTR. Those values are then available for use by GatewayFilter Factories
 
 
Query Route Predicate Factory @@ -255,11 +255,11 @@ for details on setting up your build system with the current Spring Cloud Releas
-WebFilter Factories -Route filters allow the modification of the incoming HTTP request or outgoing HTTP response in some manner. Route filters are scoped to a particular route. Spring Cloud Gateway includes many built-in WebFilter Factories. -
-AddRequestHeader WebFilter Factory -The AddRequestHeader WebFilter Factory takes a name and value parameter. +GatewayFilter Factories +Route filters allow the modification of the incoming HTTP request or outgoing HTTP response in some manner. Route filters are scoped to a particular route. Spring Cloud Gateway includes many built-in GatewayFilter Factories. +
+AddRequestHeader GatewayFilter Factory +The AddRequestHeader GatewayFilter Factory takes a name and value parameter. application.yml @@ -276,9 +276,9 @@ for details on setting up your build system with the current Spring Cloud Releas This will add X-Request-Foo:Bar header to the downstream request’s headers for all matching requests.
-
-AddRequestParameter WebFilter Factory -The AddRequestParameter WebFilter Factory takes a name and value parameter. +
+AddRequestParameter GatewayFilter Factory +The AddRequestParameter GatewayFilter Factory takes a name and value parameter. application.yml @@ -295,9 +295,9 @@ for details on setting up your build system with the current Spring Cloud Releas This will add foo=bar to the downstream request’s query string for all matching requests.
-
-AddResponseHeader WebFilter Factory -The AddResponseHeader WebFilter Factory takes a name and value parameter. +
+AddResponseHeader GatewayFilter Factory +The AddResponseHeader GatewayFilter Factory takes a name and value parameter. application.yml @@ -314,9 +314,9 @@ for details on setting up your build system with the current Spring Cloud Releas This will add X-Response-Foo:Bar header to the downstream response’s headers for all matching requests.
-
-Hystrix WebFilter Factory -The Hystrix WebFilter Factory takes a single name parameters, which is the name of the HystrixCommand. (More options might be added in future releases). +
+Hystrix GatewayFilter Factory +The Hystrix GatewayFilter Factory takes a single name parameters, which is the name of the HystrixCommand. (More options might be added in future releases). application.yml @@ -333,9 +333,9 @@ for details on setting up your build system with the current Spring Cloud Releas This wraps the remaining filters in a HystrixCommand with command name myCommandName.
-
-PrefixPath WebFilter Factory -The PrefixPath WebFilter Factory takes a single prefix parameter. +
+PrefixPath GatewayFilter Factory +The PrefixPath GatewayFilter Factory takes a single prefix parameter. application.yml @@ -352,9 +352,9 @@ for details on setting up your build system with the current Spring Cloud Releas This will prefix /mypath to the path of all matching requests. So a request to /hello, would be sent to /mypath/hello.
-
-RequestRateLimiter WebFilter Factory -The RequestRateLimiter WebFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName. +
+RequestRateLimiter GatewayFilter Factory +The RequestRateLimiter GatewayFilter Factory takes three parameters: replenishRate, burstCapacity & keyResolverName. replenishRate is how many requests per second do you want a user to be allowed to do. burstCapacity TODO: document burst capacity keyResolverName is the name of a bean that implements the KeyResolver interface. @@ -393,9 +393,9 @@ KeyResolver userKeyResolver() { This defines a request rate limit of 10 per user. The KeyResolver is a simple one that gets the user request parameter (note: this is not recommended for production).
-
-RedirectTo WebFilter Factory -The RedirectTo WebFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header. +
+RedirectTo GatewayFilter Factory +The RedirectTo GatewayFilter Factory takes a status and a url parameter. The status should be a 300 series redirect http code, such as 301. The url should be a valid url. This will be the value of the Location header. application.yml @@ -412,9 +412,9 @@ KeyResolver userKeyResolver() { This will send a status 302 with a Location:http://acme.org header to perform a redirect.
-
-RemoveNonProxyHeaders WebFilter Factory -The RemoveNonProxyHeaders WebFilter Factory removes headers from forwarded requests. The default list of headers that is removed comes from the IETF. +
+RemoveNonProxyHeaders GatewayFilter Factory +The RemoveNonProxyHeaders GatewayFilter Factory removes headers from forwarded requests. The default list of headers that is removed comes from the IETF. The default removed headers are: @@ -444,9 +444,9 @@ KeyResolver userKeyResolver() { To change this, set the spring.cloud.gateway.filter.remove-non-proxy-headers.headers property to the list of header names to remove.
-
-RemoveRequestHeader WebFilter Factory -The RemoveRequestHeader WebFilter Factory takes a name parameter. It is the name of the header to be removed. +
+RemoveRequestHeader GatewayFilter Factory +The RemoveRequestHeader GatewayFilter Factory takes a name parameter. It is the name of the header to be removed. application.yml @@ -463,9 +463,9 @@ KeyResolver userKeyResolver() { This will remove the X-Request-Foo header before it is sent downstream.
-
-RemoveResponseHeader WebFilter Factory -The RemoveResponseHeader WebFilter Factory takes a name parameter. It is the name of the header to be removed. +
+RemoveResponseHeader GatewayFilter Factory +The RemoveResponseHeader GatewayFilter Factory takes a name parameter. It is the name of the header to be removed. application.yml @@ -482,9 +482,9 @@ KeyResolver userKeyResolver() { This will remove the X-Response-Foo header from the response before it is returned to the gateway client.
-
-RewritePath WebFilter Factory -The RewritePath WebFilter Factory takes a path regexp parameter and a replacement parameter. This uses Java regular expressions for a flexible way to rewrite the request path. +
+RewritePath GatewayFilter Factory +The RewritePath GatewayFilter Factory takes a path regexp parameter and a replacement parameter. This uses Java regular expressions for a flexible way to rewrite the request path. application.yml @@ -502,9 +502,9 @@ KeyResolver userKeyResolver() { 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.
-
-SecureHeaders WebFilter Factory -The SecureHeaders WebFilter Factory adds a number of headers to the response at the reccomendation from this blog post. +
+SecureHeaders GatewayFilter Factory +The SecureHeaders GatewayFilter Factory adds a number of headers to the response at the reccomendation from this blog post. The following headers are added (allong with default values): @@ -561,9 +561,9 @@ KeyResolver userKeyResolver() {
-
-SetPath WebFilter Factory -The SetPath WebFilter 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. +
+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 @@ -582,9 +582,9 @@ KeyResolver userKeyResolver() { For a request path of /foo/bar, this will set the path to /bar before making the downstream request.
-
-SetResponseHeader WebFilter Factory -The SetResponseHeader WebFilter Factory takes name and value parameters. +
+SetResponseHeader GatewayFilter Factory +The SetResponseHeader GatewayFilter Factory takes name and value parameters. application.yml @@ -599,11 +599,11 @@ KeyResolver userKeyResolver() { - SetResponseHeader=X-Response-Foo, Bar -This WebFilter replaces all headers with the given name, rather than adding. So if the downstream server responded with a X-Response-Foo:1234, this would be replaced with X-Response-Foo:Bar, which is what the gateway client would receive. +This GatewayFilter replaces all headers with the given name, rather than adding. So if the downstream server responded with a X-Response-Foo:1234, this would be replaced with X-Response-Foo:Bar, which is what the gateway client would receive.
-
-SetStatus WebFilter Factory -The SetStatus WebFilter 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. +
+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 @@ -627,9 +627,9 @@ KeyResolver userKeyResolver() { Global Filters -The GlobalFilter interface has the same signature as WebFilter. These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones). -
-Combined Global Filter and WebFilter Ordering +The GlobalFilter interface has the same signature as GatewayFilter. These are special filters that are conditionally applied to all routes. (This interface and usage are subject to change in future milestones). +
+Combined Global Filter and GatewayFilter Ordering TODO: document ordering
@@ -697,9 +697,9 @@ KeyResolver userKeyResolver() { Config.java -// static imports from WebFilterFactories and RoutePredicates +// static imports from GatewayFilters and RoutePredicates @Bean -public RouteLocator customRouteLocator(ThrottleWebFilterFactory throttle) { +public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) { return Routes.locator() .route("test") .uri("http://httpbin.org:80") @@ -729,9 +729,9 @@ public RouteLocator customRouteLocator(ThrottleWebFilterFactory throttle) { Writing Custom Route Predicate Factories TODO: document writing Custom Route Predicate Factories
-
-Writing Custom WebFilter Factories -TODO: document writing Custom WebFilter Factories +
+Writing Custom GatewayFilter Factories +TODO: document writing Custom GatewayFilter Factories
Writing Custom Global Filters