Sync docs from master to gh-pages

This commit is contained in:
buildmaster
2020-01-22 04:41:46 +00:00
parent 250acfa438
commit 231fe2bb8f
2 changed files with 210 additions and 482 deletions

View File

@@ -124,37 +124,36 @@ $(addBlockSwitches);
<li><a href="#the-addrequestparameter-gatewayfilter-factory">5.2. The <code>AddRequestParameter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-addresponseheader-gatewayfilter-factory">5.3. The <code>AddResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-deduperesponseheader-gatewayfilter-factory">5.4. The <code>DedupeResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#hystrix">5.5. The Hystrix <code>GatewayFilter</code> Factory</a></li>
<li><a href="#spring-cloud-circuitbreaker-filter-factory">5.6. Spring Cloud CircuitBreaker GatewayFilter Factory</a></li>
<li><a href="#fallback-headers">5.7. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-maprequestheader-gatewayfilter-factory">5.8. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-prefixpath-gatewayfilter-factory">5.9. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-preservehostheader-gatewayfilter-factory">5.10. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestratelimiter-gatewayfilter-factory">5.11. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a>
<li><a href="#spring-cloud-circuitbreaker-filter-factory">5.5. Spring Cloud CircuitBreaker GatewayFilter Factory</a></li>
<li><a href="#fallback-headers">5.6. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-maprequestheader-gatewayfilter-factory">5.7. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-prefixpath-gatewayfilter-factory">5.8. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-preservehostheader-gatewayfilter-factory">5.9. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestratelimiter-gatewayfilter-factory">5.10. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a>
<ul class="sectlevel3">
<li><a href="#the-redis-ratelimiter">5.11.1. The Redis <code>RateLimiter</code></a></li>
<li><a href="#the-redis-ratelimiter">5.10.1. The Redis <code>RateLimiter</code></a></li>
</ul>
</li>
<li><a href="#the-redirectto-gatewayfilter-factory">5.12. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.13. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestheader-gatewayfilter-factory">5.14. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></li>
<li><a href="#removeresponseheader-gatewayfilter-factory">5.15. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestparameter-gatewayfilter-factory">5.16. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewritepath-gatewayfilter-factory">5.17. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#rewritelocationresponseheader-gatewayfilter-factory">5.18. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewriteresponseheader-gatewayfilter-factory">5.19. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-savesession-gatewayfilter-factory">5.20. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-secureheaders-gatewayfilter-factory">5.21. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setpath-gatewayfilter-factory">5.22. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setrequestheader-gatewayfilter-factory">5.23. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setresponseheader-gatewayfilter-factory">5.24. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setstatus-gatewayfilter-factory">5.25. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-stripprefix-gatewayfilter-factory">5.26. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-retry-gatewayfilter-factory">5.27. The Retry <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestsize-gatewayfilter-factory">5.28. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-request-body-gatewayfilter-factory">5.29. Modify a Request Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-response-body-gatewayfilter-factory">5.30. Modify a Response Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#default-filters">5.31. Default Filters</a></li>
<li><a href="#the-redirectto-gatewayfilter-factory">5.11. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.12. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestheader-gatewayfilter-factory">5.13. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></li>
<li><a href="#removeresponseheader-gatewayfilter-factory">5.14. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestparameter-gatewayfilter-factory">5.15. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewritepath-gatewayfilter-factory">5.16. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#rewritelocationresponseheader-gatewayfilter-factory">5.17. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewriteresponseheader-gatewayfilter-factory">5.18. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-savesession-gatewayfilter-factory">5.19. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-secureheaders-gatewayfilter-factory">5.20. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setpath-gatewayfilter-factory">5.21. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setrequestheader-gatewayfilter-factory">5.22. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setresponseheader-gatewayfilter-factory">5.23. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setstatus-gatewayfilter-factory">5.24. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-stripprefix-gatewayfilter-factory">5.25. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-retry-gatewayfilter-factory">5.26. The Retry <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestsize-gatewayfilter-factory">5.27. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-request-body-gatewayfilter-factory">5.28. Modify a Request Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-response-body-gatewayfilter-factory">5.29. Modify a Response Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#default-filters">5.30. Default Filters</a></li>
</ul>
</li>
<li><a href="#global-filters">6. Global Filters</a>
@@ -231,7 +230,7 @@ $(addBlockSwitches);
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p><strong>2.2.2.BUILD-SNAPSHOT</strong></p>
<p><strong>3.0.0.BUILD-SNAPSHOT</strong></p>
</div>
<div class="paragraph">
<p>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.</p>
@@ -997,142 +996,7 @@ The accepted values are <code>RETAIN_FIRST</code> (default), <code>RETAIN_LAST</
</div>
</div>
<div class="sect2">
<h3 id="hystrix"><a class="anchor" href="#hystrix"></a><a class="link" href="#hystrix">5.5. The Hystrix <code>GatewayFilter</code> Factory</a></h3>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<a href="https://cloud.spring.io/spring-cloud-netflix/multi/multi__modules_in_maintenance_mode.html">Netflix has put Hystrix in maintenance mode</a>. We suggest you use the <a href="#spring-cloud-circuitbreaker-filter-factory">Spring Cloud CircuitBreaker
Gateway Filter</a> with Resilience4J, as support for Hystrix will be removed in a future release.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p><a href="https://github.com/Netflix/Hystrix">Hystrix</a> is a library from Netflix that implements the <a href="https://martinfowler.com/bliki/CircuitBreaker.html">circuit breaker pattern</a>.
The Hystrix <code>GatewayFilter</code> lets you introduce circuit breakers to your gateway routes, protecting your services from cascading failures and letting you provide fallback responses in the event of downstream failures.</p>
</div>
<div class="paragraph">
<p>To enable Hystrix <code>GatewayFilter</code> instances in your project, add a dependency on <code>spring-cloud-starter-netflix-hystrix</code> from <a href="https://cloud.spring.io/spring-cloud-netflix/">Spring Cloud Netflix</a>.</p>
</div>
<div class="paragraph">
<p>The Hystrix <code>GatewayFilter</code> factory requires a single <code>name</code> parameter, which is the name of the <code>HystrixCommand</code>.
The following example configures a Hystrix <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 20. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">spring:
cloud:
gateway:
routes:
- id: hystrix_route
uri: https://example.org
filters:
- Hystrix=myCommandName</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>This wraps the remaining filters in a <code>HystrixCommand</code> with a command name of <code>myCommandName</code>.</p>
</div>
<div class="paragraph">
<p>The Hystrix filter can also accept an optional <code>fallbackUri</code> parameter. Currently, only <code>forward:</code> schemed URIs are supported. If the fallback is called, the request is forwarded to the controller matched by the URI.
The following example configures such a fallback:</p>
</div>
<div class="exampleblock">
<div class="title">Example 21. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">spring:
cloud:
gateway:
routes:
- id: hystrix_route
uri: lb://backing-service:8088
predicates:
- Path=/consumingserviceendpoint
filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/incaseoffailureusethis
- RewritePath=/consumingserviceendpoint, /backingserviceendpoint</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>This will forward to the <code>/incaseoffailureusethis</code> URI when the Hystrix fallback is called. Note that this example also demonstrates (optional) Spring Cloud Netflix Ribbon load-balancing (defined the <code>lb</code> prefix on the destination URI).</p>
</div>
<div class="paragraph">
<p>The primary scenario is to use the <code>fallbackUri</code> to an internal controller or handler within the gateway app.
However, you can also reroute the request to a controller or handler in an external application, as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 22. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">spring:
cloud:
gateway:
routes:
- id: ingredients
uri: lb://ingredients
predicates:
- Path=//ingredients/**
filters:
- name: Hystrix
args:
name: fetchIngredients
fallbackUri: forward:/fallback
- id: ingredients-fallback
uri: http://localhost:9994
predicates:
- Path=/fallback</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In this example, there is no <code>fallback</code> endpoint or handler in the gateway application.
However, there is one in another application, registered under <code><a href="http://localhost:9994" class="bare">localhost:9994</a></code>.</p>
</div>
<div class="paragraph">
<p>In case of the request being forwarded to the fallback, the Hystrix Gateway filter also provides the <code>Throwable</code> that has caused it.
It is added to the <code>ServerWebExchange</code> as the <code>ServerWebExchangeUtils.HYSTRIX_EXECUTION_EXCEPTION_ATTR</code> attribute, which you can use when handling the fallback within the gateway application.</p>
</div>
<div class="paragraph">
<p>For the external controller/handler scenario, you can add headers with exception details.
You can find more information on doing so in the <a href="#fallback-headers">FallbackHeaders GatewayFilter Factory section</a>.</p>
</div>
<div class="paragraph">
<p>You can configured Hystrix settings (such as timeouts) with global defaults or on a route-by-route basis by using application properties, as explained on the <a href="https://github.com/Netflix/Hystrix/wiki/Configuration">Hystrix wiki</a>.</p>
</div>
<div class="paragraph">
<p>To set a five-second timeout for the example route shown earlier, you could use the following configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 23. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">hystrix.command.fallbackcmd.execution.isolation.thread.timeoutInMilliseconds: 5000</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="spring-cloud-circuitbreaker-filter-factory"><a class="anchor" href="#spring-cloud-circuitbreaker-filter-factory"></a><a class="link" href="#spring-cloud-circuitbreaker-filter-factory">5.6. Spring Cloud CircuitBreaker GatewayFilter Factory</a></h3>
<h3 id="spring-cloud-circuitbreaker-filter-factory"><a class="anchor" href="#spring-cloud-circuitbreaker-filter-factory"></a><a class="link" href="#spring-cloud-circuitbreaker-filter-factory">5.5. Spring Cloud CircuitBreaker GatewayFilter Factory</a></h3>
<div class="paragraph">
<p>The Spring Cloud CircuitBreaker GatewayFilter factory uses the Spring Cloud CircuitBreaker APIs to wrap Gateway routes in
a circuit breaker. Spring Cloud CircuitBreaker supports two libraries that can be used with Spring Cloud Gateway, Hystrix
@@ -1143,7 +1007,7 @@ and Resilience4J. Since Netflix has placed Hystrix in maintenance-only mode, we
The following example configures a Spring Cloud CircuitBreaker <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 24. application.yml</div>
<div class="title">Example 20. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1179,7 +1043,7 @@ If the fallback is called, the request is forwarded to the controller matched by
The following example configures such a fallback:</p>
</div>
<div class="exampleblock">
<div class="title">Example 25. application.yml</div>
<div class="title">Example 21. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1205,7 +1069,7 @@ The following example configures such a fallback:</p>
<p>The following listing does the same thing in Java:</p>
</div>
<div class="exampleblock">
<div class="title">Example 26. Application.java</div>
<div class="title">Example 22. Application.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1230,7 +1094,7 @@ Note that this example also demonstrates the (optional) Spring Cloud Netflix Rib
However, you can also reroute the request to a controller or handler in an external application, as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 27. application.yml</div>
<div class="title">Example 23. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1269,12 +1133,12 @@ You can find more information on doing so in the <a href="#fallback-headers">Fa
</div>
</div>
<div class="sect2">
<h3 id="fallback-headers"><a class="anchor" href="#fallback-headers"></a><a class="link" href="#fallback-headers">5.7. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="fallback-headers"><a class="anchor" href="#fallback-headers"></a><a class="link" href="#fallback-headers">5.6. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>FallbackHeaders</code> factory lets you add Hystrix or Spring Cloud CircuitBreaker execution exception details in the headers of a request forwarded to a <code>fallbackUri</code> in an external application, as in the following scenario:</p>
</div>
<div class="exampleblock">
<div class="title">Example 28. application.yml</div>
<div class="title">Example 24. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1331,7 +1195,7 @@ The headers with the exception type, message and (if available) root cause excep
</div>
</div>
<div class="sect2">
<h3 id="the-maprequestheader-gatewayfilter-factory"><a class="anchor" href="#the-maprequestheader-gatewayfilter-factory"></a><a class="link" href="#the-maprequestheader-gatewayfilter-factory">5.8. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-maprequestheader-gatewayfilter-factory"><a class="anchor" href="#the-maprequestheader-gatewayfilter-factory"></a><a class="link" href="#the-maprequestheader-gatewayfilter-factory">5.7. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>MapRequestHeader</code> <code>GatewayFilter</code> factory takes <code>fromHeader</code> and <code>toHeader</code> parameters.
It creates a new named header (<code>toHeader</code>), and the value is extracted out of an existing named header (<code>fromHeader</code>) from the incoming http request.
@@ -1340,7 +1204,7 @@ If the new named header already exists, its values are augmented with the new va
The following example configures a <code>MapRequestHeader</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 29. application.yml</div>
<div class="title">Example 25. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1361,13 +1225,13 @@ The following example configures a <code>MapRequestHeader</code>:</p>
</div>
</div>
<div class="sect2">
<h3 id="the-prefixpath-gatewayfilter-factory"><a class="anchor" href="#the-prefixpath-gatewayfilter-factory"></a><a class="link" href="#the-prefixpath-gatewayfilter-factory">5.9. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-prefixpath-gatewayfilter-factory"><a class="anchor" href="#the-prefixpath-gatewayfilter-factory"></a><a class="link" href="#the-prefixpath-gatewayfilter-factory">5.8. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>PrefixPath</code> <code>GatewayFilter</code> factory takes a single <code>prefix</code> parameter.
The following example configures a <code>PrefixPath</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 30. application.yml</div>
<div class="title">Example 26. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1389,14 +1253,14 @@ So a request to <code>/hello</code> would be sent to <code>/mypath/hello</code>.
</div>
</div>
<div class="sect2">
<h3 id="the-preservehostheader-gatewayfilter-factory"><a class="anchor" href="#the-preservehostheader-gatewayfilter-factory"></a><a class="link" href="#the-preservehostheader-gatewayfilter-factory">5.10. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-preservehostheader-gatewayfilter-factory"><a class="anchor" href="#the-preservehostheader-gatewayfilter-factory"></a><a class="link" href="#the-preservehostheader-gatewayfilter-factory">5.9. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>PreserveHostHeader</code> <code>GatewayFilter</code> factory has no parameters.
This filter sets a request attribute that the routing filter inspects to determine if the original host header should be sent, rather than the host header determined by the HTTP client.
The following example configures a <code>PreserveHostHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 31. application.yml</div>
<div class="title">Example 27. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1414,7 +1278,7 @@ The following example configures a <code>PreserveHostHeader</code> <code>Gateway
</div>
</div>
<div class="sect2">
<h3 id="the-requestratelimiter-gatewayfilter-factory"><a class="anchor" href="#the-requestratelimiter-gatewayfilter-factory"></a><a class="link" href="#the-requestratelimiter-gatewayfilter-factory">5.11. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-requestratelimiter-gatewayfilter-factory"><a class="anchor" href="#the-requestratelimiter-gatewayfilter-factory"></a><a class="link" href="#the-requestratelimiter-gatewayfilter-factory">5.10. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RequestRateLimiter</code> <code>GatewayFilter</code> factory uses a <code>RateLimiter</code> implementation to determine if the current request is allowed to proceed. If it is not, a status of <code>HTTP 429 - Too Many Requests</code> (by default) is returned.</p>
</div>
@@ -1428,7 +1292,7 @@ In configuration, reference the bean by name using SpEL.
The following listing shows the <code>KeyResolver</code> interface:</p>
</div>
<div class="exampleblock">
<div class="title">Example 32. KeyResolver.java</div>
<div class="title">Example 28. KeyResolver.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1461,7 +1325,7 @@ You can adjust this behavior by setting the <code>spring.cloud.gateway.filter.re
<p>The <code>RequestRateLimiter</code> is not configurable with the "shortcut" notation. The following example below is <em>invalid</em>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 33. application.properties</div>
<div class="title">Example 29. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1476,7 +1340,7 @@ spring.cloud.gateway.routes[0].filters[0]=RequestRateLimiter=2, 2, #{@userkeyres
</table>
</div>
<div class="sect3">
<h4 id="the-redis-ratelimiter"><a class="anchor" href="#the-redis-ratelimiter"></a><a class="link" href="#the-redis-ratelimiter">5.11.1. The Redis <code>RateLimiter</code></a></h4>
<h4 id="the-redis-ratelimiter"><a class="anchor" href="#the-redis-ratelimiter"></a><a class="link" href="#the-redis-ratelimiter">5.10.1. The Redis <code>RateLimiter</code></a></h4>
<div class="paragraph">
<p>The Redis implementation is based off of work done at <a href="https://stripe.com/blog/rate-limiters">Stripe</a>.
It requires the use of the <code>spring-boot-starter-data-redis-reactive</code> Spring Boot starter.</p>
@@ -1500,7 +1364,7 @@ In this case, the rate limiter needs to be allowed some time between bursts (acc
The following listing configures a <code>redis-rate-limiter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 34. application.yml</div>
<div class="title">Example 30. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1523,7 +1387,7 @@ The following listing configures a <code>redis-rate-limiter</code>:</p>
<p>The following example configures a KeyResolver in Java:</p>
</div>
<div class="exampleblock">
<div class="title">Example 35. Config.java</div>
<div class="title">Example 31. Config.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1546,7 +1410,7 @@ In configuration, you can reference the bean by name using SpEL.
The following listing defines a rate limiter that uses the <code>KeyResolver</code> defined in the previous listing:</p>
</div>
<div class="exampleblock">
<div class="title">Example 36. application.yml</div>
<div class="title">Example 32. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1568,7 +1432,7 @@ The following listing defines a rate limiter that uses the <code>KeyResolver</co
</div>
</div>
<div class="sect2">
<h3 id="the-redirectto-gatewayfilter-factory"><a class="anchor" href="#the-redirectto-gatewayfilter-factory"></a><a class="link" href="#the-redirectto-gatewayfilter-factory">5.12. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-redirectto-gatewayfilter-factory"><a class="anchor" href="#the-redirectto-gatewayfilter-factory"></a><a class="link" href="#the-redirectto-gatewayfilter-factory">5.11. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RedirectTo</code> <code>GatewayFilter</code> factory takes two parameters, <code>status</code> and <code>url</code>.
The <code>status</code> parameter should be a 300 series redirect HTTP code, such as 301.
@@ -1578,7 +1442,7 @@ For relative redirects, you should use <code>uri: no://op</code> as the uri of y
The following listing configures a <code>RedirectTo</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 37. application.yml</div>
<div class="title">Example 33. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1599,7 +1463,7 @@ The following listing configures a <code>RedirectTo</code> <code>GatewayFilter</
</div>
</div>
<div class="sect2">
<h3 id="the-removehopbyhopheadersfilter-gatewayfilter-factory"><a class="anchor" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory"></a><a class="link" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.13. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-removehopbyhopheadersfilter-gatewayfilter-factory"><a class="anchor" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory"></a><a class="link" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.12. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory removes headers from forwarded requests.
The default list of headers that is removed comes from the <a href="https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-7.1.3">IETF</a>.</p>
@@ -1638,14 +1502,14 @@ The default list of headers that is removed comes from the <a href="https://tool
</div>
</div>
<div class="sect2">
<h3 id="the-removerequestheader-gatewayfilter-factory"><a class="anchor" href="#the-removerequestheader-gatewayfilter-factory"></a><a class="link" href="#the-removerequestheader-gatewayfilter-factory">5.14. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></h3>
<h3 id="the-removerequestheader-gatewayfilter-factory"><a class="anchor" href="#the-removerequestheader-gatewayfilter-factory"></a><a class="link" href="#the-removerequestheader-gatewayfilter-factory">5.13. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveRequestHeader</code> <code>GatewayFilter</code> factory takes a <code>name</code> parameter.
It is the name of the header to be removed.
The following listing configures a <code>RemoveRequestHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 38. application.yml</div>
<div class="title">Example 34. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1666,14 +1530,14 @@ The following listing configures a <code>RemoveRequestHeader</code> <code>Gatewa
</div>
</div>
<div class="sect2">
<h3 id="removeresponseheader-gatewayfilter-factory"><a class="anchor" href="#removeresponseheader-gatewayfilter-factory"></a><a class="link" href="#removeresponseheader-gatewayfilter-factory">5.15. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="removeresponseheader-gatewayfilter-factory"><a class="anchor" href="#removeresponseheader-gatewayfilter-factory"></a><a class="link" href="#removeresponseheader-gatewayfilter-factory">5.14. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveResponseHeader</code> <code>GatewayFilter</code> factory takes a <code>name</code> parameter.
It is the name of the header to be removed.
The following listing configures a <code>RemoveResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 39. application.yml</div>
<div class="title">Example 35. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1698,14 +1562,14 @@ In addition, you can configure this filter once by using <code>spring.cloud.gate
</div>
</div>
<div class="sect2">
<h3 id="the-removerequestparameter-gatewayfilter-factory"><a class="anchor" href="#the-removerequestparameter-gatewayfilter-factory"></a><a class="link" href="#the-removerequestparameter-gatewayfilter-factory">5.16. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-removerequestparameter-gatewayfilter-factory"><a class="anchor" href="#the-removerequestparameter-gatewayfilter-factory"></a><a class="link" href="#the-removerequestparameter-gatewayfilter-factory">5.15. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> factory takes a <code>name</code> parameter.
It is the name of the query parameter to be removed.
The following example configures a <code>RemoveRequestParameter</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 40. application.yml</div>
<div class="title">Example 36. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1726,14 +1590,14 @@ The following example configures a <code>RemoveRequestParameter</code> <code>Gat
</div>
</div>
<div class="sect2">
<h3 id="the-rewritepath-gatewayfilter-factory"><a class="anchor" href="#the-rewritepath-gatewayfilter-factory"></a><a class="link" href="#the-rewritepath-gatewayfilter-factory">5.17. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-rewritepath-gatewayfilter-factory"><a class="anchor" href="#the-rewritepath-gatewayfilter-factory"></a><a class="link" href="#the-rewritepath-gatewayfilter-factory">5.16. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RewritePath</code> <code>GatewayFilter</code> factory takes a path <code>regexp</code> parameter and a <code>replacement</code> parameter.
This uses Java regular expressions for a flexible way to rewrite the request path.
The following listing configures a <code>RewritePath</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 41. application.yml</div>
<div class="title">Example 37. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1756,14 +1620,14 @@ The following listing configures a <code>RewritePath</code> <code>GatewayFilter<
</div>
</div>
<div class="sect2">
<h3 id="rewritelocationresponseheader-gatewayfilter-factory"><a class="anchor" href="#rewritelocationresponseheader-gatewayfilter-factory"></a><a class="link" href="#rewritelocationresponseheader-gatewayfilter-factory">5.18. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="rewritelocationresponseheader-gatewayfilter-factory"><a class="anchor" href="#rewritelocationresponseheader-gatewayfilter-factory"></a><a class="link" href="#rewritelocationresponseheader-gatewayfilter-factory">5.17. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> factory modifies the value of the <code>Location</code> response header, usually to get rid of backend-specific details.
It takes <code>stripVersionMode</code>, <code>locationHeaderName</code>, <code>hostValue</code>, and <code>protocolsRegex</code> parameters.
The following listing configures a <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 42. application.yml</div>
<div class="title">Example 38. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1809,14 +1673,14 @@ The default is <code>http|https|ftp|ftps</code>.</p>
</div>
</div>
<div class="sect2">
<h3 id="the-rewriteresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-rewriteresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-rewriteresponseheader-gatewayfilter-factory">5.19. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-rewriteresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-rewriteresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-rewriteresponseheader-gatewayfilter-factory">5.18. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> factory takes <code>name</code>, <code>regexp</code>, and <code>replacement</code> parameters.
It uses Java regular expressions for a flexible way to rewrite the response header value.
The following example configures a <code>RewriteResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 43. application.yml</div>
<div class="title">Example 39. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1838,14 +1702,14 @@ You must use <code>$\</code> to mean <code>$</code> because of the YAML specific
</div>
</div>
<div class="sect2">
<h3 id="the-savesession-gatewayfilter-factory"><a class="anchor" href="#the-savesession-gatewayfilter-factory"></a><a class="link" href="#the-savesession-gatewayfilter-factory">5.20. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-savesession-gatewayfilter-factory"><a class="anchor" href="#the-savesession-gatewayfilter-factory"></a><a class="link" href="#the-savesession-gatewayfilter-factory">5.19. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SaveSession</code> <code>GatewayFilter</code> factory forces a <code>WebSession::save</code> operation <em>before</em> forwarding the call downstream.
This is of particular use when using something like <a href="https://projects.spring.io/spring-session/">Spring Session</a> with a lazy data store and you need to ensure the session state has been saved before making the forwarded call.
The following example configures a <code>SaveSession</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 44. application.yml</div>
<div class="title">Example 40. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1868,7 +1732,7 @@ The following example configures a <code>SaveSession</code> <code>GatewayFilter<
</div>
</div>
<div class="sect2">
<h3 id="the-secureheaders-gatewayfilter-factory"><a class="anchor" href="#the-secureheaders-gatewayfilter-factory"></a><a class="link" href="#the-secureheaders-gatewayfilter-factory">5.21. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-secureheaders-gatewayfilter-factory"><a class="anchor" href="#the-secureheaders-gatewayfilter-factory"></a><a class="link" href="#the-secureheaders-gatewayfilter-factory">5.20. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SecureHeaders</code> <code>GatewayFilter</code> factory adds a number of headers to the response, per the recommendation made in <a href="https://blog.appcanary.com/2017/http-security-headers.html">this blog post</a>.</p>
</div>
@@ -1962,7 +1826,7 @@ The lowercase full name of the secure header needs to be used to disable it..
</div>
</div>
<div class="sect2">
<h3 id="the-setpath-gatewayfilter-factory"><a class="anchor" href="#the-setpath-gatewayfilter-factory"></a><a class="link" href="#the-setpath-gatewayfilter-factory">5.22. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setpath-gatewayfilter-factory"><a class="anchor" href="#the-setpath-gatewayfilter-factory"></a><a class="link" href="#the-setpath-gatewayfilter-factory">5.21. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetPath</code> <code>GatewayFilter</code> factory takes a path <code>template</code> parameter.
It offers a simple way to manipulate the request path by allowing templated segments of the path.
@@ -1971,7 +1835,7 @@ Multiple matching segments are allowed.
The following example configures a <code>SetPath</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 45. application.yml</div>
<div class="title">Example 41. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1994,13 +1858,13 @@ The following example configures a <code>SetPath</code> <code>GatewayFilter</cod
</div>
</div>
<div class="sect2">
<h3 id="the-setrequestheader-gatewayfilter-factory"><a class="anchor" href="#the-setrequestheader-gatewayfilter-factory"></a><a class="link" href="#the-setrequestheader-gatewayfilter-factory">5.23. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setrequestheader-gatewayfilter-factory"><a class="anchor" href="#the-setrequestheader-gatewayfilter-factory"></a><a class="link" href="#the-setrequestheader-gatewayfilter-factory">5.22. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetRequestHeader</code> <code>GatewayFilter</code> factory takes <code>name</code> and <code>value</code> parameters.
The following listing configures a <code>SetRequestHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 46. application.yml</div>
<div class="title">Example 42. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2026,7 +1890,7 @@ URI variables may be used in the value and are expanded at runtime.
The following example configures an <code>SetRequestHeader</code> <code>GatewayFilter</code> that uses a variable:</p>
</div>
<div class="exampleblock">
<div class="title">Example 47. application.yml</div>
<div class="title">Example 43. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2046,13 +1910,13 @@ The following example configures an <code>SetRequestHeader</code> <code>GatewayF
</div>
</div>
<div class="sect2">
<h3 id="the-setresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-setresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-setresponseheader-gatewayfilter-factory">5.24. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-setresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-setresponseheader-gatewayfilter-factory">5.23. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetResponseHeader</code> <code>GatewayFilter</code> factory takes <code>name</code> and <code>value</code> parameters.
The following listing configures a <code>SetResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 48. application.yml</div>
<div class="title">Example 44. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2078,7 +1942,7 @@ URI variables may be used in the value and will be expanded at runtime.
The following example configures an <code>SetResponseHeader</code> <code>GatewayFilter</code> that uses a variable:</p>
</div>
<div class="exampleblock">
<div class="title">Example 49. application.yml</div>
<div class="title">Example 45. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2098,7 +1962,7 @@ The following example configures an <code>SetResponseHeader</code> <code>Gateway
</div>
</div>
<div class="sect2">
<h3 id="the-setstatus-gatewayfilter-factory"><a class="anchor" href="#the-setstatus-gatewayfilter-factory"></a><a class="link" href="#the-setstatus-gatewayfilter-factory">5.25. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setstatus-gatewayfilter-factory"><a class="anchor" href="#the-setstatus-gatewayfilter-factory"></a><a class="link" href="#the-setstatus-gatewayfilter-factory">5.24. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetStatus</code> <code>GatewayFilter</code> factory takes a single parameter, <code>status</code>.
It must be a valid Spring <code>HttpStatus</code>.
@@ -2106,7 +1970,7 @@ It may be the integer value <code>404</code> or the string representation of the
The following listing configures a <code>SetStatus</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 50. application.yml</div>
<div class="title">Example 46. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2134,7 +1998,7 @@ The following listing configures a <code>SetStatus</code> <code>GatewayFilter</c
The header is added to the response if configured with the following property:</p>
</div>
<div class="exampleblock">
<div class="title">Example 51. application.yml</div>
<div class="title">Example 47. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2149,14 +2013,14 @@ The header is added to the response if configured with the following property:</
</div>
</div>
<div class="sect2">
<h3 id="the-stripprefix-gatewayfilter-factory"><a class="anchor" href="#the-stripprefix-gatewayfilter-factory"></a><a class="link" href="#the-stripprefix-gatewayfilter-factory">5.26. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-stripprefix-gatewayfilter-factory"><a class="anchor" href="#the-stripprefix-gatewayfilter-factory"></a><a class="link" href="#the-stripprefix-gatewayfilter-factory">5.25. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>StripPrefix</code> <code>GatewayFilter</code> factory takes one parameter, <code>parts</code>.
The <code>parts</code> parameter indicates the number of parts in the path to strip from the request before sending it downstream.
The following listing configures a <code>StripPrefix</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 52. application.yml</div>
<div class="title">Example 48. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2179,7 +2043,7 @@ The following listing configures a <code>StripPrefix</code> <code>GatewayFilter<
</div>
</div>
<div class="sect2">
<h3 id="the-retry-gatewayfilter-factory"><a class="anchor" href="#the-retry-gatewayfilter-factory"></a><a class="link" href="#the-retry-gatewayfilter-factory">5.27. The Retry <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-retry-gatewayfilter-factory"><a class="anchor" href="#the-retry-gatewayfilter-factory"></a><a class="link" href="#the-retry-gatewayfilter-factory">5.26. The Retry <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The Retry <code>GatewayFilter</code> factory supports the following parameters:</p>
</div>
@@ -2234,7 +2098,7 @@ If <code>basedOnPreviousValue</code> is true, the backoff is calculated byusing
<p>The following listing configures a Retry <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 53. application.yml</div>
<div class="title">Example 49. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2288,7 +2152,7 @@ Instead, it should throw an <code>Exception</code> or signal an error (for examp
</div>
</div>
<div class="sect2">
<h3 id="the-requestsize-gatewayfilter-factory"><a class="anchor" href="#the-requestsize-gatewayfilter-factory"></a><a class="link" href="#the-requestsize-gatewayfilter-factory">5.28. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-requestsize-gatewayfilter-factory"><a class="anchor" href="#the-requestsize-gatewayfilter-factory"></a><a class="link" href="#the-requestsize-gatewayfilter-factory">5.27. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>When the request size is greater than the permissible limit, the <code>RequestSize</code> <code>GatewayFilter</code> factory can restrict a request from reaching the downstream service.
The filter takes a <code>RequestSize</code> parameter.
@@ -2296,7 +2160,7 @@ It is the permissible size limit of the request defined in bytes.
The following listing configures a <code>RequestSize</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 54. application.yml</div>
<div class="title">Example 50. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2342,7 +2206,7 @@ The default request size is set to five MB if not provided as a filter argument
</div>
</div>
<div class="sect2">
<h3 id="modify-a-request-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-request-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-request-body-gatewayfilter-factory">5.29. Modify a Request Body <code>GatewayFilter</code> Factory</a></h3>
<h3 id="modify-a-request-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-request-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-request-body-gatewayfilter-factory">5.28. Modify a Request Body <code>GatewayFilter</code> Factory</a></h3>
<div class="admonitionblock caution">
<table>
<tr>
@@ -2410,7 +2274,7 @@ static class Hello {
</div>
</div>
<div class="sect2">
<h3 id="modify-a-response-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-response-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-response-body-gatewayfilter-factory">5.30. Modify a Response Body <code>GatewayFilter</code> Factory</a></h3>
<h3 id="modify-a-response-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-response-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-response-body-gatewayfilter-factory">5.29. Modify a Response Body <code>GatewayFilter</code> Factory</a></h3>
<div class="admonitionblock caution">
<table>
<tr>
@@ -2460,14 +2324,14 @@ public RouteLocator routes(RouteLocatorBuilder builder) {
</div>
</div>
<div class="sect2">
<h3 id="default-filters"><a class="anchor" href="#default-filters"></a><a class="link" href="#default-filters">5.31. Default Filters</a></h3>
<h3 id="default-filters"><a class="anchor" href="#default-filters"></a><a class="link" href="#default-filters">5.30. Default Filters</a></h3>
<div class="paragraph">
<p>To add a filter and apply it to all routes, you can use <code>spring.cloud.gateway.default-filters</code>.
This property takes a list of filters.
The following listing defines a set of default filters:</p>
</div>
<div class="exampleblock">
<div class="title">Example 55. application.yml</div>
<div class="title">Example 51. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2516,7 +2380,7 @@ This combined filter chain is sorted by the <code>org.springframework.core.Order
<p>The following listing configures a filter chain:</p>
</div>
<div class="exampleblock">
<div class="title">Example 56. ExampleConfiguration.java</div>
<div class="title">Example 52. ExampleConfiguration.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2563,7 +2427,7 @@ If so, the same rules apply.
The following listing configures a <code>LoadBalancerClientFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 57. application.yml</div>
<div class="title">Example 53. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2638,7 +2502,7 @@ If so, the same rules apply.
The following listing configures a <code>ReactiveLoadBalancerClientFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 58. application.yml</div>
<div class="title">Example 54. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2736,7 +2600,7 @@ If you use <a href="https://github.com/sockjs">SockJS</a> as a fallback over nor
<p>The following listing configures a websocket routing filter:</p>
</div>
<div class="exampleblock">
<div class="title">Example 59. application.yml</div>
<div class="title">Example 55. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2831,7 +2695,7 @@ or check if an exchange has already been routed.</p>
The following example shows how to do so:</p>
</div>
<div class="exampleblock">
<div class="title">Example 60. application.yml</div>
<div class="title">Example 56. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2851,7 +2715,7 @@ The following example shows how to do so:</p>
If you are routing to an HTTPS backend, you can configure the gateway to trust all downstream certificates with the following configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 61. application.yml</div>
<div class="title">Example 57. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2870,7 +2734,7 @@ If you are routing to an HTTPS backend, you can configure the gateway to trust a
For a production deployment, you can configure the gateway with a set of known certificates that it can trust with the following configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 62. application.yml</div>
<div class="title">Example 58. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2898,7 +2762,7 @@ A number of timeouts are associated with this handshake.
You can configure these timeouts can be configured (defaults shown) as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 63. application.yml</div>
<div class="title">Example 59. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2925,7 +2789,7 @@ You can configure these timeouts can be configured (defaults shown) as follows:<
The following listing shows the definition of the <code>RouteDefinitionLocator</code> interface:</p>
</div>
<div class="exampleblock">
<div class="title">Example 64. RouteDefinitionLocator.java</div>
<div class="title">Example 60. RouteDefinitionLocator.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2944,7 +2808,7 @@ The following listing shows the definition of the <code>RouteDefinitionLocator</
The following two examples are equivalent:</p>
</div>
<div class="exampleblock">
<div class="title">Example 65. application.yml</div>
<div class="title">Example 61. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2978,7 +2842,7 @@ The following two examples are equivalent:</p>
<p>You can configure additional parameters for each route by using metadata, as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 66. application.yml</div>
<div class="title">Example 62. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3089,7 +2953,7 @@ import static org.springframework.cloud.gateway.support.RouteMetadataUtils.RESPO
The following listing shows how it works:</p>
</div>
<div class="exampleblock">
<div class="title">Example 67. GatewaySampleApplication.java</div>
<div class="title">Example 63. GatewaySampleApplication.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3156,7 +3020,7 @@ When doing so, you need to make sure to include the default predicate and filter
The following example shows what this looks like:</p>
</div>
<div class="exampleblock">
<div class="title">Example 68. application.properties</div>
<div class="title">Example 64. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3199,7 +3063,7 @@ It must be a Java System Property, not a Spring Boot property.
<p>You can configure the logging system to have a separate access log file. The following example creates a Logback configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 69. logback.xml</div>
<div class="title">Example 65. logback.xml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3230,7 +3094,7 @@ It must be a Java System Property, not a Spring Boot property.
The following example configures CORS:</p>
</div>
<div class="exampleblock">
<div class="title">Example 70. application.yml</div>
<div class="title">Example 66. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3265,7 +3129,7 @@ To be remotely accessible, the endpoint has to be <a href="https://docs.spring.i
The following listing shows how to do so:</p>
</div>
<div class="exampleblock">
<div class="title">Example 71. application.properties</div>
<div class="title">Example 67. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3307,7 +3171,7 @@ The following example configures <code>/actuator/gateway/routes</code>:</p>
<p>This feature is enabled by default. To disable it, set the following property:</p>
</div>
<div class="exampleblock">
<div class="title">Example 72. application.properties</div>
<div class="title">Example 68. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3670,7 +3534,7 @@ You can extend an abstract class called <code>AbstractGatewayFilterFactory</code
The following examples show how to do so:</p>
</div>
<div class="exampleblock">
<div class="title">Example 73. PreGatewayFilterFactory.java</div>
<div class="title">Example 69. PreGatewayFilterFactory.java</div>
<div class="content">
<div class="listingblock">
<div class="content">

View File

@@ -124,37 +124,36 @@ $(addBlockSwitches);
<li><a href="#the-addrequestparameter-gatewayfilter-factory">5.2. The <code>AddRequestParameter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-addresponseheader-gatewayfilter-factory">5.3. The <code>AddResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-deduperesponseheader-gatewayfilter-factory">5.4. The <code>DedupeResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#hystrix">5.5. The Hystrix <code>GatewayFilter</code> Factory</a></li>
<li><a href="#spring-cloud-circuitbreaker-filter-factory">5.6. Spring Cloud CircuitBreaker GatewayFilter Factory</a></li>
<li><a href="#fallback-headers">5.7. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-maprequestheader-gatewayfilter-factory">5.8. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-prefixpath-gatewayfilter-factory">5.9. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-preservehostheader-gatewayfilter-factory">5.10. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestratelimiter-gatewayfilter-factory">5.11. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a>
<li><a href="#spring-cloud-circuitbreaker-filter-factory">5.5. Spring Cloud CircuitBreaker GatewayFilter Factory</a></li>
<li><a href="#fallback-headers">5.6. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-maprequestheader-gatewayfilter-factory">5.7. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-prefixpath-gatewayfilter-factory">5.8. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-preservehostheader-gatewayfilter-factory">5.9. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestratelimiter-gatewayfilter-factory">5.10. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a>
<ul class="sectlevel3">
<li><a href="#the-redis-ratelimiter">5.11.1. The Redis <code>RateLimiter</code></a></li>
<li><a href="#the-redis-ratelimiter">5.10.1. The Redis <code>RateLimiter</code></a></li>
</ul>
</li>
<li><a href="#the-redirectto-gatewayfilter-factory">5.12. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.13. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestheader-gatewayfilter-factory">5.14. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></li>
<li><a href="#removeresponseheader-gatewayfilter-factory">5.15. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestparameter-gatewayfilter-factory">5.16. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewritepath-gatewayfilter-factory">5.17. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#rewritelocationresponseheader-gatewayfilter-factory">5.18. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewriteresponseheader-gatewayfilter-factory">5.19. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-savesession-gatewayfilter-factory">5.20. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-secureheaders-gatewayfilter-factory">5.21. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setpath-gatewayfilter-factory">5.22. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setrequestheader-gatewayfilter-factory">5.23. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setresponseheader-gatewayfilter-factory">5.24. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setstatus-gatewayfilter-factory">5.25. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-stripprefix-gatewayfilter-factory">5.26. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-retry-gatewayfilter-factory">5.27. The Retry <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestsize-gatewayfilter-factory">5.28. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-request-body-gatewayfilter-factory">5.29. Modify a Request Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-response-body-gatewayfilter-factory">5.30. Modify a Response Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#default-filters">5.31. Default Filters</a></li>
<li><a href="#the-redirectto-gatewayfilter-factory">5.11. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.12. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestheader-gatewayfilter-factory">5.13. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></li>
<li><a href="#removeresponseheader-gatewayfilter-factory">5.14. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-removerequestparameter-gatewayfilter-factory">5.15. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewritepath-gatewayfilter-factory">5.16. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#rewritelocationresponseheader-gatewayfilter-factory">5.17. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-rewriteresponseheader-gatewayfilter-factory">5.18. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-savesession-gatewayfilter-factory">5.19. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-secureheaders-gatewayfilter-factory">5.20. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setpath-gatewayfilter-factory">5.21. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setrequestheader-gatewayfilter-factory">5.22. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setresponseheader-gatewayfilter-factory">5.23. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-setstatus-gatewayfilter-factory">5.24. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-stripprefix-gatewayfilter-factory">5.25. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-retry-gatewayfilter-factory">5.26. The Retry <code>GatewayFilter</code> Factory</a></li>
<li><a href="#the-requestsize-gatewayfilter-factory">5.27. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-request-body-gatewayfilter-factory">5.28. Modify a Request Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#modify-a-response-body-gatewayfilter-factory">5.29. Modify a Response Body <code>GatewayFilter</code> Factory</a></li>
<li><a href="#default-filters">5.30. Default Filters</a></li>
</ul>
</li>
<li><a href="#global-filters">6. Global Filters</a>
@@ -231,7 +230,7 @@ $(addBlockSwitches);
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p><strong>2.2.2.BUILD-SNAPSHOT</strong></p>
<p><strong>3.0.0.BUILD-SNAPSHOT</strong></p>
</div>
<div class="paragraph">
<p>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.</p>
@@ -997,142 +996,7 @@ The accepted values are <code>RETAIN_FIRST</code> (default), <code>RETAIN_LAST</
</div>
</div>
<div class="sect2">
<h3 id="hystrix"><a class="anchor" href="#hystrix"></a><a class="link" href="#hystrix">5.5. The Hystrix <code>GatewayFilter</code> Factory</a></h3>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<a href="https://cloud.spring.io/spring-cloud-netflix/multi/multi__modules_in_maintenance_mode.html">Netflix has put Hystrix in maintenance mode</a>. We suggest you use the <a href="#spring-cloud-circuitbreaker-filter-factory">Spring Cloud CircuitBreaker
Gateway Filter</a> with Resilience4J, as support for Hystrix will be removed in a future release.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p><a href="https://github.com/Netflix/Hystrix">Hystrix</a> is a library from Netflix that implements the <a href="https://martinfowler.com/bliki/CircuitBreaker.html">circuit breaker pattern</a>.
The Hystrix <code>GatewayFilter</code> lets you introduce circuit breakers to your gateway routes, protecting your services from cascading failures and letting you provide fallback responses in the event of downstream failures.</p>
</div>
<div class="paragraph">
<p>To enable Hystrix <code>GatewayFilter</code> instances in your project, add a dependency on <code>spring-cloud-starter-netflix-hystrix</code> from <a href="https://cloud.spring.io/spring-cloud-netflix/">Spring Cloud Netflix</a>.</p>
</div>
<div class="paragraph">
<p>The Hystrix <code>GatewayFilter</code> factory requires a single <code>name</code> parameter, which is the name of the <code>HystrixCommand</code>.
The following example configures a Hystrix <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 20. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">spring:
cloud:
gateway:
routes:
- id: hystrix_route
uri: https://example.org
filters:
- Hystrix=myCommandName</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>This wraps the remaining filters in a <code>HystrixCommand</code> with a command name of <code>myCommandName</code>.</p>
</div>
<div class="paragraph">
<p>The Hystrix filter can also accept an optional <code>fallbackUri</code> parameter. Currently, only <code>forward:</code> schemed URIs are supported. If the fallback is called, the request is forwarded to the controller matched by the URI.
The following example configures such a fallback:</p>
</div>
<div class="exampleblock">
<div class="title">Example 21. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">spring:
cloud:
gateway:
routes:
- id: hystrix_route
uri: lb://backing-service:8088
predicates:
- Path=/consumingserviceendpoint
filters:
- name: Hystrix
args:
name: fallbackcmd
fallbackUri: forward:/incaseoffailureusethis
- RewritePath=/consumingserviceendpoint, /backingserviceendpoint</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>This will forward to the <code>/incaseoffailureusethis</code> URI when the Hystrix fallback is called. Note that this example also demonstrates (optional) Spring Cloud Netflix Ribbon load-balancing (defined the <code>lb</code> prefix on the destination URI).</p>
</div>
<div class="paragraph">
<p>The primary scenario is to use the <code>fallbackUri</code> to an internal controller or handler within the gateway app.
However, you can also reroute the request to a controller or handler in an external application, as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 22. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">spring:
cloud:
gateway:
routes:
- id: ingredients
uri: lb://ingredients
predicates:
- Path=//ingredients/**
filters:
- name: Hystrix
args:
name: fetchIngredients
fallbackUri: forward:/fallback
- id: ingredients-fallback
uri: http://localhost:9994
predicates:
- Path=/fallback</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In this example, there is no <code>fallback</code> endpoint or handler in the gateway application.
However, there is one in another application, registered under <code><a href="http://localhost:9994" class="bare">localhost:9994</a></code>.</p>
</div>
<div class="paragraph">
<p>In case of the request being forwarded to the fallback, the Hystrix Gateway filter also provides the <code>Throwable</code> that has caused it.
It is added to the <code>ServerWebExchange</code> as the <code>ServerWebExchangeUtils.HYSTRIX_EXECUTION_EXCEPTION_ATTR</code> attribute, which you can use when handling the fallback within the gateway application.</p>
</div>
<div class="paragraph">
<p>For the external controller/handler scenario, you can add headers with exception details.
You can find more information on doing so in the <a href="#fallback-headers">FallbackHeaders GatewayFilter Factory section</a>.</p>
</div>
<div class="paragraph">
<p>You can configured Hystrix settings (such as timeouts) with global defaults or on a route-by-route basis by using application properties, as explained on the <a href="https://github.com/Netflix/Hystrix/wiki/Configuration">Hystrix wiki</a>.</p>
</div>
<div class="paragraph">
<p>To set a five-second timeout for the example route shown earlier, you could use the following configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 23. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-yaml hljs" data-lang="yaml">hystrix.command.fallbackcmd.execution.isolation.thread.timeoutInMilliseconds: 5000</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="spring-cloud-circuitbreaker-filter-factory"><a class="anchor" href="#spring-cloud-circuitbreaker-filter-factory"></a><a class="link" href="#spring-cloud-circuitbreaker-filter-factory">5.6. Spring Cloud CircuitBreaker GatewayFilter Factory</a></h3>
<h3 id="spring-cloud-circuitbreaker-filter-factory"><a class="anchor" href="#spring-cloud-circuitbreaker-filter-factory"></a><a class="link" href="#spring-cloud-circuitbreaker-filter-factory">5.5. Spring Cloud CircuitBreaker GatewayFilter Factory</a></h3>
<div class="paragraph">
<p>The Spring Cloud CircuitBreaker GatewayFilter factory uses the Spring Cloud CircuitBreaker APIs to wrap Gateway routes in
a circuit breaker. Spring Cloud CircuitBreaker supports two libraries that can be used with Spring Cloud Gateway, Hystrix
@@ -1143,7 +1007,7 @@ and Resilience4J. Since Netflix has placed Hystrix in maintenance-only mode, we
The following example configures a Spring Cloud CircuitBreaker <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 24. application.yml</div>
<div class="title">Example 20. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1179,7 +1043,7 @@ If the fallback is called, the request is forwarded to the controller matched by
The following example configures such a fallback:</p>
</div>
<div class="exampleblock">
<div class="title">Example 25. application.yml</div>
<div class="title">Example 21. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1205,7 +1069,7 @@ The following example configures such a fallback:</p>
<p>The following listing does the same thing in Java:</p>
</div>
<div class="exampleblock">
<div class="title">Example 26. Application.java</div>
<div class="title">Example 22. Application.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1230,7 +1094,7 @@ Note that this example also demonstrates the (optional) Spring Cloud Netflix Rib
However, you can also reroute the request to a controller or handler in an external application, as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 27. application.yml</div>
<div class="title">Example 23. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1269,12 +1133,12 @@ You can find more information on doing so in the <a href="#fallback-headers">Fa
</div>
</div>
<div class="sect2">
<h3 id="fallback-headers"><a class="anchor" href="#fallback-headers"></a><a class="link" href="#fallback-headers">5.7. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="fallback-headers"><a class="anchor" href="#fallback-headers"></a><a class="link" href="#fallback-headers">5.6. The <code>FallbackHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>FallbackHeaders</code> factory lets you add Hystrix or Spring Cloud CircuitBreaker execution exception details in the headers of a request forwarded to a <code>fallbackUri</code> in an external application, as in the following scenario:</p>
</div>
<div class="exampleblock">
<div class="title">Example 28. application.yml</div>
<div class="title">Example 24. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1331,7 +1195,7 @@ The headers with the exception type, message and (if available) root cause excep
</div>
</div>
<div class="sect2">
<h3 id="the-maprequestheader-gatewayfilter-factory"><a class="anchor" href="#the-maprequestheader-gatewayfilter-factory"></a><a class="link" href="#the-maprequestheader-gatewayfilter-factory">5.8. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-maprequestheader-gatewayfilter-factory"><a class="anchor" href="#the-maprequestheader-gatewayfilter-factory"></a><a class="link" href="#the-maprequestheader-gatewayfilter-factory">5.7. The <code>MapRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>MapRequestHeader</code> <code>GatewayFilter</code> factory takes <code>fromHeader</code> and <code>toHeader</code> parameters.
It creates a new named header (<code>toHeader</code>), and the value is extracted out of an existing named header (<code>fromHeader</code>) from the incoming http request.
@@ -1340,7 +1204,7 @@ If the new named header already exists, its values are augmented with the new va
The following example configures a <code>MapRequestHeader</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 29. application.yml</div>
<div class="title">Example 25. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1361,13 +1225,13 @@ The following example configures a <code>MapRequestHeader</code>:</p>
</div>
</div>
<div class="sect2">
<h3 id="the-prefixpath-gatewayfilter-factory"><a class="anchor" href="#the-prefixpath-gatewayfilter-factory"></a><a class="link" href="#the-prefixpath-gatewayfilter-factory">5.9. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-prefixpath-gatewayfilter-factory"><a class="anchor" href="#the-prefixpath-gatewayfilter-factory"></a><a class="link" href="#the-prefixpath-gatewayfilter-factory">5.8. The <code>PrefixPath</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>PrefixPath</code> <code>GatewayFilter</code> factory takes a single <code>prefix</code> parameter.
The following example configures a <code>PrefixPath</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 30. application.yml</div>
<div class="title">Example 26. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1389,14 +1253,14 @@ So a request to <code>/hello</code> would be sent to <code>/mypath/hello</code>.
</div>
</div>
<div class="sect2">
<h3 id="the-preservehostheader-gatewayfilter-factory"><a class="anchor" href="#the-preservehostheader-gatewayfilter-factory"></a><a class="link" href="#the-preservehostheader-gatewayfilter-factory">5.10. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-preservehostheader-gatewayfilter-factory"><a class="anchor" href="#the-preservehostheader-gatewayfilter-factory"></a><a class="link" href="#the-preservehostheader-gatewayfilter-factory">5.9. The <code>PreserveHostHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>PreserveHostHeader</code> <code>GatewayFilter</code> factory has no parameters.
This filter sets a request attribute that the routing filter inspects to determine if the original host header should be sent, rather than the host header determined by the HTTP client.
The following example configures a <code>PreserveHostHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 31. application.yml</div>
<div class="title">Example 27. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1414,7 +1278,7 @@ The following example configures a <code>PreserveHostHeader</code> <code>Gateway
</div>
</div>
<div class="sect2">
<h3 id="the-requestratelimiter-gatewayfilter-factory"><a class="anchor" href="#the-requestratelimiter-gatewayfilter-factory"></a><a class="link" href="#the-requestratelimiter-gatewayfilter-factory">5.11. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-requestratelimiter-gatewayfilter-factory"><a class="anchor" href="#the-requestratelimiter-gatewayfilter-factory"></a><a class="link" href="#the-requestratelimiter-gatewayfilter-factory">5.10. The <code>RequestRateLimiter</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RequestRateLimiter</code> <code>GatewayFilter</code> factory uses a <code>RateLimiter</code> implementation to determine if the current request is allowed to proceed. If it is not, a status of <code>HTTP 429 - Too Many Requests</code> (by default) is returned.</p>
</div>
@@ -1428,7 +1292,7 @@ In configuration, reference the bean by name using SpEL.
The following listing shows the <code>KeyResolver</code> interface:</p>
</div>
<div class="exampleblock">
<div class="title">Example 32. KeyResolver.java</div>
<div class="title">Example 28. KeyResolver.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1461,7 +1325,7 @@ You can adjust this behavior by setting the <code>spring.cloud.gateway.filter.re
<p>The <code>RequestRateLimiter</code> is not configurable with the "shortcut" notation. The following example below is <em>invalid</em>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 33. application.properties</div>
<div class="title">Example 29. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1476,7 +1340,7 @@ spring.cloud.gateway.routes[0].filters[0]=RequestRateLimiter=2, 2, #{@userkeyres
</table>
</div>
<div class="sect3">
<h4 id="the-redis-ratelimiter"><a class="anchor" href="#the-redis-ratelimiter"></a><a class="link" href="#the-redis-ratelimiter">5.11.1. The Redis <code>RateLimiter</code></a></h4>
<h4 id="the-redis-ratelimiter"><a class="anchor" href="#the-redis-ratelimiter"></a><a class="link" href="#the-redis-ratelimiter">5.10.1. The Redis <code>RateLimiter</code></a></h4>
<div class="paragraph">
<p>The Redis implementation is based off of work done at <a href="https://stripe.com/blog/rate-limiters">Stripe</a>.
It requires the use of the <code>spring-boot-starter-data-redis-reactive</code> Spring Boot starter.</p>
@@ -1500,7 +1364,7 @@ In this case, the rate limiter needs to be allowed some time between bursts (acc
The following listing configures a <code>redis-rate-limiter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 34. application.yml</div>
<div class="title">Example 30. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1523,7 +1387,7 @@ The following listing configures a <code>redis-rate-limiter</code>:</p>
<p>The following example configures a KeyResolver in Java:</p>
</div>
<div class="exampleblock">
<div class="title">Example 35. Config.java</div>
<div class="title">Example 31. Config.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1546,7 +1410,7 @@ In configuration, you can reference the bean by name using SpEL.
The following listing defines a rate limiter that uses the <code>KeyResolver</code> defined in the previous listing:</p>
</div>
<div class="exampleblock">
<div class="title">Example 36. application.yml</div>
<div class="title">Example 32. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1568,7 +1432,7 @@ The following listing defines a rate limiter that uses the <code>KeyResolver</co
</div>
</div>
<div class="sect2">
<h3 id="the-redirectto-gatewayfilter-factory"><a class="anchor" href="#the-redirectto-gatewayfilter-factory"></a><a class="link" href="#the-redirectto-gatewayfilter-factory">5.12. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-redirectto-gatewayfilter-factory"><a class="anchor" href="#the-redirectto-gatewayfilter-factory"></a><a class="link" href="#the-redirectto-gatewayfilter-factory">5.11. The <code>RedirectTo</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RedirectTo</code> <code>GatewayFilter</code> factory takes two parameters, <code>status</code> and <code>url</code>.
The <code>status</code> parameter should be a 300 series redirect HTTP code, such as 301.
@@ -1578,7 +1442,7 @@ For relative redirects, you should use <code>uri: no://op</code> as the uri of y
The following listing configures a <code>RedirectTo</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 37. application.yml</div>
<div class="title">Example 33. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1599,7 +1463,7 @@ The following listing configures a <code>RedirectTo</code> <code>GatewayFilter</
</div>
</div>
<div class="sect2">
<h3 id="the-removehopbyhopheadersfilter-gatewayfilter-factory"><a class="anchor" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory"></a><a class="link" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.13. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-removehopbyhopheadersfilter-gatewayfilter-factory"><a class="anchor" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory"></a><a class="link" href="#the-removehopbyhopheadersfilter-gatewayfilter-factory">5.12. The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveHopByHopHeadersFilter</code> <code>GatewayFilter</code> Factory removes headers from forwarded requests.
The default list of headers that is removed comes from the <a href="https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-7.1.3">IETF</a>.</p>
@@ -1638,14 +1502,14 @@ The default list of headers that is removed comes from the <a href="https://tool
</div>
</div>
<div class="sect2">
<h3 id="the-removerequestheader-gatewayfilter-factory"><a class="anchor" href="#the-removerequestheader-gatewayfilter-factory"></a><a class="link" href="#the-removerequestheader-gatewayfilter-factory">5.14. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></h3>
<h3 id="the-removerequestheader-gatewayfilter-factory"><a class="anchor" href="#the-removerequestheader-gatewayfilter-factory"></a><a class="link" href="#the-removerequestheader-gatewayfilter-factory">5.13. The <code>RemoveRequestHeader</code> GatewayFilter Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveRequestHeader</code> <code>GatewayFilter</code> factory takes a <code>name</code> parameter.
It is the name of the header to be removed.
The following listing configures a <code>RemoveRequestHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 38. application.yml</div>
<div class="title">Example 34. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1666,14 +1530,14 @@ The following listing configures a <code>RemoveRequestHeader</code> <code>Gatewa
</div>
</div>
<div class="sect2">
<h3 id="removeresponseheader-gatewayfilter-factory"><a class="anchor" href="#removeresponseheader-gatewayfilter-factory"></a><a class="link" href="#removeresponseheader-gatewayfilter-factory">5.15. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="removeresponseheader-gatewayfilter-factory"><a class="anchor" href="#removeresponseheader-gatewayfilter-factory"></a><a class="link" href="#removeresponseheader-gatewayfilter-factory">5.14. <code>RemoveResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveResponseHeader</code> <code>GatewayFilter</code> factory takes a <code>name</code> parameter.
It is the name of the header to be removed.
The following listing configures a <code>RemoveResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 39. application.yml</div>
<div class="title">Example 35. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1698,14 +1562,14 @@ In addition, you can configure this filter once by using <code>spring.cloud.gate
</div>
</div>
<div class="sect2">
<h3 id="the-removerequestparameter-gatewayfilter-factory"><a class="anchor" href="#the-removerequestparameter-gatewayfilter-factory"></a><a class="link" href="#the-removerequestparameter-gatewayfilter-factory">5.16. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-removerequestparameter-gatewayfilter-factory"><a class="anchor" href="#the-removerequestparameter-gatewayfilter-factory"></a><a class="link" href="#the-removerequestparameter-gatewayfilter-factory">5.15. The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RemoveRequestParameter</code> <code>GatewayFilter</code> factory takes a <code>name</code> parameter.
It is the name of the query parameter to be removed.
The following example configures a <code>RemoveRequestParameter</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 40. application.yml</div>
<div class="title">Example 36. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1726,14 +1590,14 @@ The following example configures a <code>RemoveRequestParameter</code> <code>Gat
</div>
</div>
<div class="sect2">
<h3 id="the-rewritepath-gatewayfilter-factory"><a class="anchor" href="#the-rewritepath-gatewayfilter-factory"></a><a class="link" href="#the-rewritepath-gatewayfilter-factory">5.17. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-rewritepath-gatewayfilter-factory"><a class="anchor" href="#the-rewritepath-gatewayfilter-factory"></a><a class="link" href="#the-rewritepath-gatewayfilter-factory">5.16. The <code>RewritePath</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RewritePath</code> <code>GatewayFilter</code> factory takes a path <code>regexp</code> parameter and a <code>replacement</code> parameter.
This uses Java regular expressions for a flexible way to rewrite the request path.
The following listing configures a <code>RewritePath</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 41. application.yml</div>
<div class="title">Example 37. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1756,14 +1620,14 @@ The following listing configures a <code>RewritePath</code> <code>GatewayFilter<
</div>
</div>
<div class="sect2">
<h3 id="rewritelocationresponseheader-gatewayfilter-factory"><a class="anchor" href="#rewritelocationresponseheader-gatewayfilter-factory"></a><a class="link" href="#rewritelocationresponseheader-gatewayfilter-factory">5.18. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="rewritelocationresponseheader-gatewayfilter-factory"><a class="anchor" href="#rewritelocationresponseheader-gatewayfilter-factory"></a><a class="link" href="#rewritelocationresponseheader-gatewayfilter-factory">5.17. <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code> factory modifies the value of the <code>Location</code> response header, usually to get rid of backend-specific details.
It takes <code>stripVersionMode</code>, <code>locationHeaderName</code>, <code>hostValue</code>, and <code>protocolsRegex</code> parameters.
The following listing configures a <code>RewriteLocationResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 42. application.yml</div>
<div class="title">Example 38. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1809,14 +1673,14 @@ The default is <code>http|https|ftp|ftps</code>.</p>
</div>
</div>
<div class="sect2">
<h3 id="the-rewriteresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-rewriteresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-rewriteresponseheader-gatewayfilter-factory">5.19. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-rewriteresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-rewriteresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-rewriteresponseheader-gatewayfilter-factory">5.18. The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>RewriteResponseHeader</code> <code>GatewayFilter</code> factory takes <code>name</code>, <code>regexp</code>, and <code>replacement</code> parameters.
It uses Java regular expressions for a flexible way to rewrite the response header value.
The following example configures a <code>RewriteResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 43. application.yml</div>
<div class="title">Example 39. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1838,14 +1702,14 @@ You must use <code>$\</code> to mean <code>$</code> because of the YAML specific
</div>
</div>
<div class="sect2">
<h3 id="the-savesession-gatewayfilter-factory"><a class="anchor" href="#the-savesession-gatewayfilter-factory"></a><a class="link" href="#the-savesession-gatewayfilter-factory">5.20. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-savesession-gatewayfilter-factory"><a class="anchor" href="#the-savesession-gatewayfilter-factory"></a><a class="link" href="#the-savesession-gatewayfilter-factory">5.19. The <code>SaveSession</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SaveSession</code> <code>GatewayFilter</code> factory forces a <code>WebSession::save</code> operation <em>before</em> forwarding the call downstream.
This is of particular use when using something like <a href="https://projects.spring.io/spring-session/">Spring Session</a> with a lazy data store and you need to ensure the session state has been saved before making the forwarded call.
The following example configures a <code>SaveSession</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 44. application.yml</div>
<div class="title">Example 40. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1868,7 +1732,7 @@ The following example configures a <code>SaveSession</code> <code>GatewayFilter<
</div>
</div>
<div class="sect2">
<h3 id="the-secureheaders-gatewayfilter-factory"><a class="anchor" href="#the-secureheaders-gatewayfilter-factory"></a><a class="link" href="#the-secureheaders-gatewayfilter-factory">5.21. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-secureheaders-gatewayfilter-factory"><a class="anchor" href="#the-secureheaders-gatewayfilter-factory"></a><a class="link" href="#the-secureheaders-gatewayfilter-factory">5.20. The <code>SecureHeaders</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SecureHeaders</code> <code>GatewayFilter</code> factory adds a number of headers to the response, per the recommendation made in <a href="https://blog.appcanary.com/2017/http-security-headers.html">this blog post</a>.</p>
</div>
@@ -1962,7 +1826,7 @@ The lowercase full name of the secure header needs to be used to disable it..
</div>
</div>
<div class="sect2">
<h3 id="the-setpath-gatewayfilter-factory"><a class="anchor" href="#the-setpath-gatewayfilter-factory"></a><a class="link" href="#the-setpath-gatewayfilter-factory">5.22. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setpath-gatewayfilter-factory"><a class="anchor" href="#the-setpath-gatewayfilter-factory"></a><a class="link" href="#the-setpath-gatewayfilter-factory">5.21. The <code>SetPath</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetPath</code> <code>GatewayFilter</code> factory takes a path <code>template</code> parameter.
It offers a simple way to manipulate the request path by allowing templated segments of the path.
@@ -1971,7 +1835,7 @@ Multiple matching segments are allowed.
The following example configures a <code>SetPath</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 45. application.yml</div>
<div class="title">Example 41. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -1994,13 +1858,13 @@ The following example configures a <code>SetPath</code> <code>GatewayFilter</cod
</div>
</div>
<div class="sect2">
<h3 id="the-setrequestheader-gatewayfilter-factory"><a class="anchor" href="#the-setrequestheader-gatewayfilter-factory"></a><a class="link" href="#the-setrequestheader-gatewayfilter-factory">5.23. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setrequestheader-gatewayfilter-factory"><a class="anchor" href="#the-setrequestheader-gatewayfilter-factory"></a><a class="link" href="#the-setrequestheader-gatewayfilter-factory">5.22. The <code>SetRequestHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetRequestHeader</code> <code>GatewayFilter</code> factory takes <code>name</code> and <code>value</code> parameters.
The following listing configures a <code>SetRequestHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 46. application.yml</div>
<div class="title">Example 42. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2026,7 +1890,7 @@ URI variables may be used in the value and are expanded at runtime.
The following example configures an <code>SetRequestHeader</code> <code>GatewayFilter</code> that uses a variable:</p>
</div>
<div class="exampleblock">
<div class="title">Example 47. application.yml</div>
<div class="title">Example 43. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2046,13 +1910,13 @@ The following example configures an <code>SetRequestHeader</code> <code>GatewayF
</div>
</div>
<div class="sect2">
<h3 id="the-setresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-setresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-setresponseheader-gatewayfilter-factory">5.24. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setresponseheader-gatewayfilter-factory"><a class="anchor" href="#the-setresponseheader-gatewayfilter-factory"></a><a class="link" href="#the-setresponseheader-gatewayfilter-factory">5.23. The <code>SetResponseHeader</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetResponseHeader</code> <code>GatewayFilter</code> factory takes <code>name</code> and <code>value</code> parameters.
The following listing configures a <code>SetResponseHeader</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 48. application.yml</div>
<div class="title">Example 44. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2078,7 +1942,7 @@ URI variables may be used in the value and will be expanded at runtime.
The following example configures an <code>SetResponseHeader</code> <code>GatewayFilter</code> that uses a variable:</p>
</div>
<div class="exampleblock">
<div class="title">Example 49. application.yml</div>
<div class="title">Example 45. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2098,7 +1962,7 @@ The following example configures an <code>SetResponseHeader</code> <code>Gateway
</div>
</div>
<div class="sect2">
<h3 id="the-setstatus-gatewayfilter-factory"><a class="anchor" href="#the-setstatus-gatewayfilter-factory"></a><a class="link" href="#the-setstatus-gatewayfilter-factory">5.25. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-setstatus-gatewayfilter-factory"><a class="anchor" href="#the-setstatus-gatewayfilter-factory"></a><a class="link" href="#the-setstatus-gatewayfilter-factory">5.24. The <code>SetStatus</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>SetStatus</code> <code>GatewayFilter</code> factory takes a single parameter, <code>status</code>.
It must be a valid Spring <code>HttpStatus</code>.
@@ -2106,7 +1970,7 @@ It may be the integer value <code>404</code> or the string representation of the
The following listing configures a <code>SetStatus</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 50. application.yml</div>
<div class="title">Example 46. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2134,7 +1998,7 @@ The following listing configures a <code>SetStatus</code> <code>GatewayFilter</c
The header is added to the response if configured with the following property:</p>
</div>
<div class="exampleblock">
<div class="title">Example 51. application.yml</div>
<div class="title">Example 47. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2149,14 +2013,14 @@ The header is added to the response if configured with the following property:</
</div>
</div>
<div class="sect2">
<h3 id="the-stripprefix-gatewayfilter-factory"><a class="anchor" href="#the-stripprefix-gatewayfilter-factory"></a><a class="link" href="#the-stripprefix-gatewayfilter-factory">5.26. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-stripprefix-gatewayfilter-factory"><a class="anchor" href="#the-stripprefix-gatewayfilter-factory"></a><a class="link" href="#the-stripprefix-gatewayfilter-factory">5.25. The <code>StripPrefix</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The <code>StripPrefix</code> <code>GatewayFilter</code> factory takes one parameter, <code>parts</code>.
The <code>parts</code> parameter indicates the number of parts in the path to strip from the request before sending it downstream.
The following listing configures a <code>StripPrefix</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 52. application.yml</div>
<div class="title">Example 48. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2179,7 +2043,7 @@ The following listing configures a <code>StripPrefix</code> <code>GatewayFilter<
</div>
</div>
<div class="sect2">
<h3 id="the-retry-gatewayfilter-factory"><a class="anchor" href="#the-retry-gatewayfilter-factory"></a><a class="link" href="#the-retry-gatewayfilter-factory">5.27. The Retry <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-retry-gatewayfilter-factory"><a class="anchor" href="#the-retry-gatewayfilter-factory"></a><a class="link" href="#the-retry-gatewayfilter-factory">5.26. The Retry <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>The Retry <code>GatewayFilter</code> factory supports the following parameters:</p>
</div>
@@ -2234,7 +2098,7 @@ If <code>basedOnPreviousValue</code> is true, the backoff is calculated byusing
<p>The following listing configures a Retry <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 53. application.yml</div>
<div class="title">Example 49. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2288,7 +2152,7 @@ Instead, it should throw an <code>Exception</code> or signal an error (for examp
</div>
</div>
<div class="sect2">
<h3 id="the-requestsize-gatewayfilter-factory"><a class="anchor" href="#the-requestsize-gatewayfilter-factory"></a><a class="link" href="#the-requestsize-gatewayfilter-factory">5.28. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></h3>
<h3 id="the-requestsize-gatewayfilter-factory"><a class="anchor" href="#the-requestsize-gatewayfilter-factory"></a><a class="link" href="#the-requestsize-gatewayfilter-factory">5.27. The <code>RequestSize</code> <code>GatewayFilter</code> Factory</a></h3>
<div class="paragraph">
<p>When the request size is greater than the permissible limit, the <code>RequestSize</code> <code>GatewayFilter</code> factory can restrict a request from reaching the downstream service.
The filter takes a <code>RequestSize</code> parameter.
@@ -2296,7 +2160,7 @@ It is the permissible size limit of the request defined in bytes.
The following listing configures a <code>RequestSize</code> <code>GatewayFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 54. application.yml</div>
<div class="title">Example 50. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2342,7 +2206,7 @@ The default request size is set to five MB if not provided as a filter argument
</div>
</div>
<div class="sect2">
<h3 id="modify-a-request-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-request-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-request-body-gatewayfilter-factory">5.29. Modify a Request Body <code>GatewayFilter</code> Factory</a></h3>
<h3 id="modify-a-request-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-request-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-request-body-gatewayfilter-factory">5.28. Modify a Request Body <code>GatewayFilter</code> Factory</a></h3>
<div class="admonitionblock caution">
<table>
<tr>
@@ -2410,7 +2274,7 @@ static class Hello {
</div>
</div>
<div class="sect2">
<h3 id="modify-a-response-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-response-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-response-body-gatewayfilter-factory">5.30. Modify a Response Body <code>GatewayFilter</code> Factory</a></h3>
<h3 id="modify-a-response-body-gatewayfilter-factory"><a class="anchor" href="#modify-a-response-body-gatewayfilter-factory"></a><a class="link" href="#modify-a-response-body-gatewayfilter-factory">5.29. Modify a Response Body <code>GatewayFilter</code> Factory</a></h3>
<div class="admonitionblock caution">
<table>
<tr>
@@ -2460,14 +2324,14 @@ public RouteLocator routes(RouteLocatorBuilder builder) {
</div>
</div>
<div class="sect2">
<h3 id="default-filters"><a class="anchor" href="#default-filters"></a><a class="link" href="#default-filters">5.31. Default Filters</a></h3>
<h3 id="default-filters"><a class="anchor" href="#default-filters"></a><a class="link" href="#default-filters">5.30. Default Filters</a></h3>
<div class="paragraph">
<p>To add a filter and apply it to all routes, you can use <code>spring.cloud.gateway.default-filters</code>.
This property takes a list of filters.
The following listing defines a set of default filters:</p>
</div>
<div class="exampleblock">
<div class="title">Example 55. application.yml</div>
<div class="title">Example 51. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2516,7 +2380,7 @@ This combined filter chain is sorted by the <code>org.springframework.core.Order
<p>The following listing configures a filter chain:</p>
</div>
<div class="exampleblock">
<div class="title">Example 56. ExampleConfiguration.java</div>
<div class="title">Example 52. ExampleConfiguration.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2563,7 +2427,7 @@ If so, the same rules apply.
The following listing configures a <code>LoadBalancerClientFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 57. application.yml</div>
<div class="title">Example 53. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2638,7 +2502,7 @@ If so, the same rules apply.
The following listing configures a <code>ReactiveLoadBalancerClientFilter</code>:</p>
</div>
<div class="exampleblock">
<div class="title">Example 58. application.yml</div>
<div class="title">Example 54. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2736,7 +2600,7 @@ If you use <a href="https://github.com/sockjs">SockJS</a> as a fallback over nor
<p>The following listing configures a websocket routing filter:</p>
</div>
<div class="exampleblock">
<div class="title">Example 59. application.yml</div>
<div class="title">Example 55. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2831,7 +2695,7 @@ or check if an exchange has already been routed.</p>
The following example shows how to do so:</p>
</div>
<div class="exampleblock">
<div class="title">Example 60. application.yml</div>
<div class="title">Example 56. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2851,7 +2715,7 @@ The following example shows how to do so:</p>
If you are routing to an HTTPS backend, you can configure the gateway to trust all downstream certificates with the following configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 61. application.yml</div>
<div class="title">Example 57. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2870,7 +2734,7 @@ If you are routing to an HTTPS backend, you can configure the gateway to trust a
For a production deployment, you can configure the gateway with a set of known certificates that it can trust with the following configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 62. application.yml</div>
<div class="title">Example 58. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2898,7 +2762,7 @@ A number of timeouts are associated with this handshake.
You can configure these timeouts can be configured (defaults shown) as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 63. application.yml</div>
<div class="title">Example 59. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2925,7 +2789,7 @@ You can configure these timeouts can be configured (defaults shown) as follows:<
The following listing shows the definition of the <code>RouteDefinitionLocator</code> interface:</p>
</div>
<div class="exampleblock">
<div class="title">Example 64. RouteDefinitionLocator.java</div>
<div class="title">Example 60. RouteDefinitionLocator.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2944,7 +2808,7 @@ The following listing shows the definition of the <code>RouteDefinitionLocator</
The following two examples are equivalent:</p>
</div>
<div class="exampleblock">
<div class="title">Example 65. application.yml</div>
<div class="title">Example 61. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -2978,7 +2842,7 @@ The following two examples are equivalent:</p>
<p>You can configure additional parameters for each route by using metadata, as follows:</p>
</div>
<div class="exampleblock">
<div class="title">Example 66. application.yml</div>
<div class="title">Example 62. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3089,7 +2953,7 @@ import static org.springframework.cloud.gateway.support.RouteMetadataUtils.RESPO
The following listing shows how it works:</p>
</div>
<div class="exampleblock">
<div class="title">Example 67. GatewaySampleApplication.java</div>
<div class="title">Example 63. GatewaySampleApplication.java</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3156,7 +3020,7 @@ When doing so, you need to make sure to include the default predicate and filter
The following example shows what this looks like:</p>
</div>
<div class="exampleblock">
<div class="title">Example 68. application.properties</div>
<div class="title">Example 64. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3199,7 +3063,7 @@ It must be a Java System Property, not a Spring Boot property.
<p>You can configure the logging system to have a separate access log file. The following example creates a Logback configuration:</p>
</div>
<div class="exampleblock">
<div class="title">Example 69. logback.xml</div>
<div class="title">Example 65. logback.xml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3230,7 +3094,7 @@ It must be a Java System Property, not a Spring Boot property.
The following example configures CORS:</p>
</div>
<div class="exampleblock">
<div class="title">Example 70. application.yml</div>
<div class="title">Example 66. application.yml</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3265,7 +3129,7 @@ To be remotely accessible, the endpoint has to be <a href="https://docs.spring.i
The following listing shows how to do so:</p>
</div>
<div class="exampleblock">
<div class="title">Example 71. application.properties</div>
<div class="title">Example 67. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3307,7 +3171,7 @@ The following example configures <code>/actuator/gateway/routes</code>:</p>
<p>This feature is enabled by default. To disable it, set the following property:</p>
</div>
<div class="exampleblock">
<div class="title">Example 72. application.properties</div>
<div class="title">Example 68. application.properties</div>
<div class="content">
<div class="listingblock">
<div class="content">
@@ -3670,7 +3534,7 @@ You can extend an abstract class called <code>AbstractGatewayFilterFactory</code
The following examples show how to do so:</p>
</div>
<div class="exampleblock">
<div class="title">Example 73. PreGatewayFilterFactory.java</div>
<div class="title">Example 69. PreGatewayFilterFactory.java</div>
<div class="content">
<div class="listingblock">
<div class="content">