Merge branch 'main' of https://github.com/Ebolo1/spring-cloud-gateway into Doc-spring-api-gateway-server-mvc

This commit is contained in:
ehesmiley
2025-02-19 15:12:18 +01:00
192 changed files with 3454 additions and 325 deletions

2
.github/dco.yml vendored Normal file
View File

@@ -0,0 +1,2 @@
require:
members: false

View File

@@ -40,15 +40,11 @@ tracker for issues and merging pull requests into main. If you want
to contribute even something trivial please do not hesitate, but
follow the guidelines below.
[[sign-the-contributor-license-agreement]]
== Sign the Contributor License Agreement
[[developer-certificate-of-origin]]
== Developer Certificate of Origin (DCO)
Before we accept a non-trivial patch or pull request we will need you to sign the
https://cla.pivotal.io/sign/spring[Contributor License Agreement].
Signing the contributor's agreement does not grant anyone commit rights to the main
repository, but it does mean that we can accept your contributions, and you will get an
author credit if we do. Active contributors might be asked to join the core team, and
given the ability to merge pull requests.
All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin.
For additional details, please refer to the blog post https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring[Hello DCO, Goodbye CLA: Simplifying Contributions to Spring].
[[code-of-conduct]]
== Code of Conduct

View File

@@ -6,7 +6,7 @@ nav:
ext:
collector:
run:
command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests
command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests -DdisableConfigurationProperties
local: true
scan:
dir: ./target/classes/antora-resources/

View File

@@ -1,116 +1,116 @@
* xref:index.adoc[Introduction]
// begin Gateway Reactive Server
// begin Gateway Server WebFlux
* xref:spring-cloud-gateway.adoc[]
** xref:spring-cloud-gateway/starter.adoc[]
** xref:spring-cloud-gateway/glossary.adoc[]
** xref:spring-cloud-gateway/how-it-works.adoc[]
** xref:spring-cloud-gateway/configuring-route-predicate-factories-and-filter-factories.adoc[]
** xref:spring-cloud-gateway/request-predicates-factories.adoc[]
** xref:spring-cloud-gateway/gatewayfilter-factories.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/addrequestheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/addrequestheadersifnotpresent-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/addrequestparameter-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/addresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/circuitbreaker-filter-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/cacherequestbody-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/deduperesponseheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/fallback-headers.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/jsontogrpc-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/local-cache-response-filter.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/maprequestheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/modifyrequestbody-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/modifyresponsebody-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/prefixpath-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/preservehostheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/redirectto-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/removejsonattributesresponsebody-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/removerequestheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/removerequestparameter-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/removeresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/requestheadersize-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/requestratelimiter-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/rewritelocationresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/rewritepath-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/rewriterequestparameter-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/rewriteresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/savesession-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/secureheaders-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/setpath-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/setrequestheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/setresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/setstatus-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/stripprefix-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/retry-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/requestsize-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/setrequesthostheader-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/tokenrelay-factory.adoc[]
*** xref:spring-cloud-gateway/gatewayfilter-factories/default-filters.adoc[]
** xref:spring-cloud-gateway/global-filters.adoc[]
** xref:spring-cloud-gateway/httpheadersfilters.adoc[]
** xref:spring-cloud-gateway/tls-and-ssl.adoc[]
** xref:spring-cloud-gateway/http-client.adoc[]
** xref:spring-cloud-gateway/configuration.adoc[]
** xref:spring-cloud-gateway/route-metadata-configuration.adoc[]
** xref:spring-cloud-gateway/http-timeouts-configuration.adoc[]
** xref:spring-cloud-gateway/fluent-java-routes-api.adoc[]
** xref:spring-cloud-gateway/the-discoveryclient-route-definition-locator.adoc[]
** xref:spring-cloud-gateway/reactor-netty-access-logs.adoc[]
** xref:spring-cloud-gateway/cors-configuration.adoc[]
** xref:spring-cloud-gateway/actuator-api.adoc[]
** xref:spring-cloud-gateway/sharing-routes.adoc[]
** xref:spring-cloud-gateway/troubleshooting.adoc[]
** xref:spring-cloud-gateway/developer-guide.adoc[]
** xref:spring-cloud-gateway/aot-and-native-image-support.adoc[]
** xref:spring-cloud-gateway/configuration-properties.adoc[]
* xref:spring-cloud-gateway-server-webflux.adoc[]
** xref:spring-cloud-gateway-server-webflux/starter.adoc[]
** xref:spring-cloud-gateway-server-webflux/glossary.adoc[]
** xref:spring-cloud-gateway-server-webflux/how-it-works.adoc[]
** xref:spring-cloud-gateway-server-webflux/configuring-route-predicate-factories-and-filter-factories.adoc[]
** xref:spring-cloud-gateway-server-webflux/request-predicates-factories.adoc[]
** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/addrequestheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/addrequestheadersifnotpresent-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/addrequestparameter-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/addresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/circuitbreaker-filter-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/cacherequestbody-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/deduperesponseheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/fallback-headers.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/jsontogrpc-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/local-cache-response-filter.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/maprequestheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/modifyrequestbody-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/modifyresponsebody-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/prefixpath-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/preservehostheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/redirectto-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/removejsonattributesresponsebody-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/removerequestheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/removerequestparameter-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/removeresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/requestheadersize-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/requestratelimiter-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/rewritelocationresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/rewritepath-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/rewriterequestparameter-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/rewriteresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/savesession-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/secureheaders-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/setpath-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/setrequestheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/setresponseheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/setstatus-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/stripprefix-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/retry-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/requestsize-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/setrequesthostheader-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/tokenrelay-factory.adoc[]
*** xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/default-filters.adoc[]
** xref:spring-cloud-gateway-server-webflux/global-filters.adoc[]
** xref:spring-cloud-gateway-server-webflux/httpheadersfilters.adoc[]
** xref:spring-cloud-gateway-server-webflux/tls-and-ssl.adoc[]
** xref:spring-cloud-gateway-server-webflux/http-client.adoc[]
** xref:spring-cloud-gateway-server-webflux/configuration.adoc[]
** xref:spring-cloud-gateway-server-webflux/route-metadata-configuration.adoc[]
** xref:spring-cloud-gateway-server-webflux/http-timeouts-configuration.adoc[]
** xref:spring-cloud-gateway-server-webflux/fluent-java-routes-api.adoc[]
** xref:spring-cloud-gateway-server-webflux/the-discoveryclient-route-definition-locator.adoc[]
** xref:spring-cloud-gateway-server-webflux/reactor-netty-access-logs.adoc[]
** xref:spring-cloud-gateway-server-webflux/cors-configuration.adoc[]
** xref:spring-cloud-gateway-server-webflux/actuator-api.adoc[]
** xref:spring-cloud-gateway-server-webflux/sharing-routes.adoc[]
** xref:spring-cloud-gateway-server-webflux/troubleshooting.adoc[]
** xref:spring-cloud-gateway-server-webflux/developer-guide.adoc[]
** xref:spring-cloud-gateway-server-webflux/aot-and-native-image-support.adoc[]
** xref:spring-cloud-gateway-server-webflux/configuration-properties.adoc[]
// begin Gateway Server MVC
// begin Gateway Server Web MVC
* xref:spring-cloud-gateway-server-mvc.adoc[]
** xref:spring-cloud-gateway-server-mvc/starter.adoc[]
** xref:spring-cloud-gateway-server-mvc/glossary.adoc[]
** xref:spring-cloud-gateway-server-mvc/how-it-works.adoc[]
** xref:spring-cloud-gateway-server-mvc/java-routes-api.adoc[]
** xref:spring-cloud-gateway-server-mvc/gateway-request-predicates.adoc[]
** xref:spring-cloud-gateway-server-mvc/gateway-handler-filter-functions.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/addrequestheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/addrequestheadersifnotpresent.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/addrequestparameter.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/addresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/circuitbreaker-filter.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/deduperesponseheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/fallback-headers.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/loadbalancer.adoc[]
* xref:spring-cloud-gateway-server-webmvc.adoc[]
** xref:spring-cloud-gateway-server-webmvc/starter.adoc[]
** xref:spring-cloud-gateway-server-webmvc/glossary.adoc[]
** xref:spring-cloud-gateway-server-webmvc/how-it-works.adoc[]
** xref:spring-cloud-gateway-server-webmvc/java-routes-api.adoc[]
** xref:spring-cloud-gateway-server-webmvc/gateway-request-predicates.adoc[]
** xref:spring-cloud-gateway-server-webmvc/gateway-handler-filter-functions.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/addrequestheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/addrequestheadersifnotpresent.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/addrequestparameter.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/addresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/circuitbreaker-filter.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/deduperesponseheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/fallback-headers.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/loadbalancer.adoc[]
//*** xref:spring-cloud-gateway-server-mvc/filters/local-cache-response-filter.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/maprequestheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/modifyrequestbody.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/modifyresponsebody.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/prefixpath.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/preservehostheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/redirectto.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/maprequestheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/modifyrequestbody.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/modifyresponsebody.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/prefixpath.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/preservehostheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/redirectto.adoc[]
//*** xref:spring-cloud-gateway-server-mvc/filters/removejsonattributesresponsebody.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/removerequestheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/removerequestparameter.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/removeresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/requestheadersize.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/ratelimiter.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/rewritelocationresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/rewritepath.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/removerequestheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/removerequestparameter.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/removeresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/requestheadersize.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/ratelimiter.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/rewritelocationresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/rewritepath.adoc[]
//*** xref:spring-cloud-gateway-server-mvc/filters/rewriterequestparameter.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/rewriteresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/rewriteresponseheader.adoc[]
//*** xref:spring-cloud-gateway-server-mvc/filters/savesession.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/setpath.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/setrequestheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/setresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/setstatus.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/stripprefix.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/retry.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/requestsize.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/setrequesthostheader.adoc[]
*** xref:spring-cloud-gateway-server-mvc/filters/tokenrelay.adoc[]
** xref:spring-cloud-gateway-server-mvc/writing-custom-predicates-and-filters.adoc[]
** xref:spring-cloud-gateway-server-mvc/working-with-servlets-and-filters.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/setpath.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/setrequestheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/setresponseheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/setstatus.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/stripprefix.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/retry.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/requestsize.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/setrequesthostheader.adoc[]
*** xref:spring-cloud-gateway-server-webmvc/filters/tokenrelay.adoc[]
** xref:spring-cloud-gateway-server-webmvc/writing-custom-predicates-and-filters.adoc[]
** xref:spring-cloud-gateway-server-webmvc/working-with-servlets-and-filters.adoc[]
// begin Gateway Proxy Exchange

View File

@@ -1,10 +1,9 @@
[[introduction]]
= Spring Cloud Gateway
// TODO: docs, rework intro for 4 modules
This project provides an API Gateway built on top of the Spring Ecosystem, including: Spring 6, Spring Boot 3 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.
There are two distinct flavors of Spring Cloud Gateway: *Server* and *Proxy Exchange*. Each flavor offers WebFlux and MVC compatibility.
There are two distinct flavors of Spring Cloud Gateway: *Server* and *Proxy Exchange*. Each flavor offers WebFlux and Web MVC compatibility.
- The Server variant is a full-featured API gateway that can be standalone or embedded in a Spring Boot application.
- The Proxy Exchange variant is exclusively for use in annotation based WebFlux or MVC applications and allows the use of a special `ProxyExchange` object as a parameter to a web handler method.
- The Proxy Exchange variant is exclusively for use in annotation based WebFlux or Web MVC applications and allows the use of a special `ProxyExchange` object as a parameter to a web handler method.

View File

@@ -1,11 +1,11 @@
[[proxy-exchange-gateway]]
= Proxy Exchange Gateway with Spring MVC or Webflux
= Proxy Exchange Gateway with Spring Web MVC or WebFlux
WARNING: The following describes an alternative style gateway. None of the Spring Cloud Gateway Server documentation applies to what follows.
== How to Include Spring Cloud Gateway Proxy Exchange
To include Spring Cloud Gateway Proxy Exchange in your project, use the artifact with a group ID of `org.springframework.cloud` and an artifact ID of `spring-cloud-gateway-mvc` for the MVC Proxy Exchange. For the WebFlux Proxy Exchange use artifact with a group ID of `org.springframework.cloud` and an artifact ID of `spring-cloud-gateway-webflux`.
To include Spring Cloud Gateway Proxy Exchange in your project, use the artifact with a group ID of `org.springframework.cloud` and an artifact ID of `spring-cloud-gateway-proxyexchange-webmvc` for the MVC Proxy Exchange. For the WebFlux Proxy Exchange use artifact with a group ID of `org.springframework.cloud` and an artifact ID of `spring-cloud-gateway-proxyexchange-webflux`.
See the https://projects.spring.io/spring-cloud/[Spring Cloud Project page] for details on setting up your build system with the current Spring Cloud Release Train.
@@ -15,7 +15,7 @@ Spring Cloud Gateway provides a utility object called `ProxyExchange`.
You can use it inside a regular Spring web handler as a method parameter.
It supports basic downstream HTTP exchanges through methods that mirror the HTTP verbs.
With MVC, it also supports forwarding to a local handler through the `forward()` method.
To use the `ProxyExchange`, include the right module in your classpath (either `spring-cloud-gateway-mvc` or `spring-cloud-gateway-webflux`).
To use the `ProxyExchange`, include the right module in your classpath (either `spring-cloud-gateway-proxyexchange-webmvc` or `spring-cloud-gateway-proxyexchange-webflux`).
The following MVC example proxies a request to `/test` downstream to a remote server:

View File

@@ -1,5 +0,0 @@
[[spring-cloud-gateway-server-mvc]]
= Spring Cloud Gateway Server MVC
:page-section-summary-toc: 1
// TODO:

View File

@@ -0,0 +1,7 @@
[[spring-cloud-gateway-server-webflux]]
= Spring Cloud Gateway Server WebFlux
:page-section-summary-toc: 1
*{spring-cloud-version}*

View File

@@ -95,13 +95,13 @@ This will default to `true` in a future release.
This section details how to retrieve route filters, including:
* xref:spring-cloud-gateway/actuator-api.adoc#gateway-global-filters[Global Filters]
* xref:spring-cloud-gateway-server-webflux/actuator-api.adoc#gateway-global-filters[Global Filters]
* <<gateway-route-filters>>
[[gateway-global-filters]]
=== Global Filters
To retrieve the xref:spring-cloud-gateway/global-filters.adoc[global filters] applied to all routes, make a `GET` request to `/actuator/gateway/globalfilters`. The resulting response is similar to the following:
To retrieve the xref:spring-cloud-gateway-server-webflux/global-filters.adoc[global filters] applied to all routes, make a `GET` request to `/actuator/gateway/globalfilters`. The resulting response is similar to the following:
----
{
@@ -117,11 +117,11 @@ To retrieve the xref:spring-cloud-gateway/global-filters.adoc[global filters] ap
----
The response contains the details of the global filters that are in place.
For each global filter, there is a string representation of the filter object (for example, `org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter@77856cc5`) and the corresponding xref:spring-cloud-gateway/global-filters.adoc#gateway-combined-global-filter-and-gatewayfilter-ordering[order] in the filter chain.
For each global filter, there is a string representation of the filter object (for example, `org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter@77856cc5`) and the corresponding xref:spring-cloud-gateway-server-webflux/global-filters.adoc#gateway-combined-global-filter-and-gatewayfilter-ordering[order] in the filter chain.
[[gateway-route-filters]]
=== Route Filters
To retrieve the xref:spring-cloud-gateway/gatewayfilter-factories.adoc[`GatewayFilter` factories] applied to routes, make a `GET` request to `/actuator/gateway/routefilters`.
To retrieve the xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories.adoc[`GatewayFilter` factories] applied to routes, make a `GET` request to `/actuator/gateway/routefilters`.
The resulting response is similar to the following:
----
@@ -215,7 +215,7 @@ The following table describes the structure of each element (each is a route) of
|`route_object.filters`
| Array
| The xref:spring-cloud-gateway/gatewayfilter-factories.adoc[`GatewayFilter` factories] applied to the route.
| The xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories.adoc[`GatewayFilter` factories] applied to the route.
|`order`
| Number
@@ -273,14 +273,14 @@ The following table describes the structure of the response:
[[creating-and-deleting-a-particular-route-definition]]
== Creating and Deleting a Particular Route Definition
To create a route definition, make a `POST` request to `/gateway/routes/\{id_route_to_create}` with a JSON body that specifies the fields of the route (see xref:spring-cloud-gateway/actuator-api.adoc#gateway-retrieving-information-about-a-particular-route[Retrieving Information about a Particular Route]).
To create a route definition, make a `POST` request to `/gateway/routes/\{id_route_to_create}` with a JSON body that specifies the fields of the route (see xref:spring-cloud-gateway-server-webflux/actuator-api.adoc#gateway-retrieving-information-about-a-particular-route[Retrieving Information about a Particular Route]).
To delete a route definition, make a `DELETE` request to `/gateway/routes/\{id_route_to_delete}`.
[[creating-multiple-route-definitions]]
== Creating multiple Route Definitions
To create multiple route definitions in a single request, make a `POST` request to `/gateway/routes` with a JSON body that specifies the fields of the route, including the route id (see xref:spring-cloud-gateway/actuator-api.adoc#gateway-retrieving-information-about-a-particular-route[Retrieving Information about a Particular Route]).
To create multiple route definitions in a single request, make a `POST` request to `/gateway/routes` with a JSON body that specifies the fields of the route, including the route id (see xref:spring-cloud-gateway-server-webflux/actuator-api.adoc#gateway-retrieving-information-about-a-particular-route[Retrieving Information about a Particular Route]).
The route definitions will be discarded if any route raises an error during the creation of the routes.

View File

@@ -121,7 +121,7 @@ In case of the request being forwarded to fallback, the Spring Cloud CircuitBrea
It is added to the `ServerWebExchange` as the `ServerWebExchangeUtils.CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR` attribute that can be used when handling the fallback within the gateway application.
For the external controller/handler scenario, headers can be added with exception details.
You can find more information on doing so in the xref:spring-cloud-gateway/gatewayfilter-factories/fallback-headers.adoc[FallbackHeaders GatewayFilter Factory section].
You can find more information on doing so in the xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/fallback-headers.adoc[FallbackHeaders GatewayFilter Factory section].
[[circuit-breaker-status-codes]]
== Tripping The Circuit Breaker On Status Codes

View File

@@ -39,5 +39,5 @@ You can overwrite the names of the headers in the configuration by setting the v
* `rootCauseExceptionTypeHeaderName` (`"Root-Cause-Exception-Type"`)
* `rootCauseExceptionMessageHeaderName` (`"Root-Cause-Exception-Message"`)
For more information on circuit breakers and the gateway see the xref:spring-cloud-gateway/gatewayfilter-factories/circuitbreaker-filter-factory.adoc[Spring Cloud CircuitBreaker Factory section].
For more information on circuit breakers and the gateway see the xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/circuitbreaker-filter-factory.adoc[Spring Cloud CircuitBreaker Factory section].

View File

@@ -8,7 +8,7 @@ This filter allows caching the response body and headers to follow these rules:
* Response data is not cached if `Cache-Control` header does not allow it (`no-store` present in the request or `no-store` or `private` present in the response).
* If the response is already cached and a new request is performed with no-cache value in `Cache-Control` header, it returns a bodiless response with 304 (Not Modified).
This filter configures the local response cache per route and is available only if the `spring.cloud.gateway.filter.local-response-cache.enabled` property is enabled. And a xref:spring-cloud-gateway/global-filters.adoc#local-cache-response-global-filter[local response cache configured globally] is also available as feature.
This filter configures the local response cache per route and is available only if the `spring.cloud.gateway.filter.local-response-cache.enabled` property is enabled. And a xref:spring-cloud-gateway-server-webflux/global-filters.adoc#local-cache-response-global-filter[local response cache configured globally] is also available as feature.
It accepts the first parameter to override the time to expire a cache entry (expressed in `s` for seconds, `m` for minutes, and `h` for hours) and a second parameter to set the maximum size of the cache to evict entries for this route (`KB`, `MB`, or `GB`).

View File

@@ -3,7 +3,7 @@
The `RequestRateLimiter` `GatewayFilter` factory uses a `RateLimiter` implementation to determine if the current request is allowed to proceed. If it is not, a status of `HTTP 429 - Too Many Requests` (by default) is returned.
This filter takes an optional `keyResolver` parameter and parameters specific to the rate limiter (described xref:spring-cloud-gateway/gatewayfilter-factories/requestratelimiter-factory.adoc#key-resolver-section[later in this section]).
This filter takes an optional `keyResolver` parameter and parameters specific to the rate limiter (described xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/requestratelimiter-factory.adoc#key-resolver-section[later in this section]).
`keyResolver` is a bean that implements the `KeyResolver` interface.
In configuration, reference the bean by name using SpEL.
@@ -27,6 +27,17 @@ The default implementation of `KeyResolver` is the `PrincipalNameKeyResolver`, w
By default, if the `KeyResolver` does not find a key, requests are denied.
You can adjust this behavior by setting the `spring.cloud.gateway.filter.request-rate-limiter.deny-empty-key` (`true` or `false`) and `spring.cloud.gateway.filter.request-rate-limiter.empty-key-status-code` properties.
The following example configures a `KeyResolver` in Java:
.Config.java
[source,java]
----
@Bean
KeyResolver userKeyResolver() {
return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user"));
}
----
[NOTE]
=====
The `RequestRateLimiter` is not configurable with the "shortcut" notation. The following example below is _invalid_:
@@ -81,6 +92,7 @@ The following listing configures a `redis-rate-limiter`:
Rate limits below `1 request/s` are accomplished by setting `replenishRate` to the wanted number of requests, `requestedTokens` to the timespan in seconds, and `burstCapacity` to the product of `replenishRate` and `requestedTokens`.
For example, setting `replenishRate=1`, `requestedTokens=60`, and `burstCapacity=60` results in a limit of `1 request/min`.
.application.yml
[source,yaml]
----
@@ -99,21 +111,87 @@ spring:
----
The following example configures a `KeyResolver` in Java:
This defines a request rate limit of 10 per user. A burst of 20 is allowed, but, in the next second, only 10 requests are available.
The `KeyResolver` is a simple one that gets the `user` request parameter
NOTE: This is not recommended for production
[[bucket4j-ratelimiter]]
== Bucket4j `RateLimiter`
This implementation is based on the https://bucket4j.com/[Bucket4j] Java library.
It requires the use of the `com.bucket4j:bucket4j_jdk17-core` dependency as well as one of the https://github.com/bucket4j/bucket4j?tab=readme-ov-file#bucket4j-distributed-features[distributed persistence options].
In this example, we will use the Caffeine integration, which is a local cache. This can be added by including the `com.github.ben-manes.caffeine:caffeine` artifact in your dependency management. The `com.bucket4j:bucket4j_jdk17-caffeine` artifact will need to be imported as well.
.pom.xml
[source,xml]
----
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>${caffeine.version}</version>
</dependency>
<dependency>
<groupId>com.bucket4j</groupId>
<artifactId>bucket4j_jdk17-caffeine</artifactId>
<version>${bucket4j.version}</version>
</dependency>
----
First a bean of type `io.github.bucket4j.distributed.proxy.AsyncProxyMananger<String>` needs to be created.
.Config.java
[source,java]
----
@Bean
KeyResolver userKeyResolver() {
return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user"));
AsyncProxyManager<String> caffeineProxyManager() {
Caffeine<String, RemoteBucketState> builder = (Caffeine) Caffeine.newBuilder().maximumSize(100);
return new CaffeineProxyManager<>(builder, Duration.ofMinutes(1)).asAsync();
}
----
This defines a request rate limit of 10 per user. A burst of 20 is allowed, but, in the next second, only 10 requests are available.
The `KeyResolver` is a simple one that gets the `user` request parameter
The `bucket4j-rate-limiter.capacity` property is the maximum number of requests a user is allowed in a single second (without any dropped requests).
This is the number of tokens the token bucket can hold.
Must be greater than zero.
The `bucket4j-rate-limiter.refillPeriod` property defines the refill period. The bucket refills at a rate of `refillTokens` per `refillPeriod`. This is a required property and uses the https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.conversion.periods[Spring Boot Period format].
The `bucket4j-rate-limiter.refillTokens` property defines how many tokens are added to the bucket in during `refillPeriod`.
This defaults to `capacity` and must be greater than or equal to zero.
The `bucket4j-rate-limiter.requestedTokens` property is how many tokens a request costs.
This is the number of tokens taken from the bucket for each request and defaults to `1`. Must be greater than zero.
The `bucket4j-rate-limiter.refillStyle` property defines how the bucket is refilled. The 3 options are `GREEDY` (default), `INTERVALLY` and `INTERVALLY_ALIGNED`.
`GREEDY` tries to add the tokens to the bucket as soon as possible. `INTERVALLY`, in opposite to greedy, waits until the whole `refillPeriod` has elapsed before refilling tokens. `INTERVALLY_ALIGNED` is like `INTERVALLY`, but with a specified `timeOfFirstRefill`.
The `bucket4j-rate-limiter.timeOfFirstRefill` property is an `Instant` only used when `refillStyle` is set to `INTERVALLY_ALIGNED`.
The following example defines a request rate limit of 10 per user. A burst of 20 is allowed, but, in the next second, only 10 requests are available.
NOTE: This is not recommended for production
.application.yml
[source,yaml]
----
spring:
cloud:
gateway:
routes:
- id: requestratelimiter_route
uri: https://example.org
filters:
- name: RequestRateLimiter
args:
bucket4j-rate-limiter.capacity: 20
bucket4j-rate-limiter.refillTokens: 10
bucket4j-rate-limiter.refillPeriod: 1s
bucket4j-rate-limiter.requestedTokens: 1
----
[[custom-ratelimiter]]
== Custom `RateLimiter`
You can also define a rate limiter as a bean that implements the `RateLimiter` interface.
In configuration, you can reference the bean by name using SpEL.
`#{@myRateLimiter}` is a SpEL expression that references a bean with named `myRateLimiter`.

View File

@@ -12,7 +12,7 @@ NOTE: This interface and its usage are subject to change in future milestone rel
When a request matches a route, the filtering web handler adds all instances of `GlobalFilter` and all route-specific instances of `GatewayFilter` to a filter chain.
This combined filter chain is sorted by the `org.springframework.core.Ordered` interface, which you can set by implementing the `getOrder()` method.
As Spring Cloud Gateway distinguishes between "`pre`" and "`post`" phases for filter logic execution (see xref:spring-cloud-gateway/how-it-works.adoc[How it Works]), the filter with the highest precedence is the first in the "`pre`"-phase and the last in the "`post`"-phase.
As Spring Cloud Gateway distinguishes between "`pre`" and "`post`" phases for filter logic execution (see xref:spring-cloud-gateway-server-webflux/how-it-works.adoc[How it Works]), the filter with the highest precedence is the first in the "`pre`"-phase and the last in the "`post`"-phase.
The following listing configures a filter chain:
@@ -86,7 +86,7 @@ This filter also implements the automatic calculation of the `max-age` value in
If `max-age` is present on the original response, the value is rewritten with the number of seconds set in the `timeToLive` configuration parameter.
In subsequent calls, this value is recalculated with the number of seconds left until the response expires.
Setting `spring.cloud.gateway.global-filter.local-response-cache.enabled` to `false` deactivate the local response cache for all routes, the xref:spring-cloud-gateway/gatewayfilter-factories/local-cache-response-filter.adoc[LocalResponseCache filter] allows to use this functionality at route level.
Setting `spring.cloud.gateway.global-filter.local-response-cache.enabled` to `false` deactivate the local response cache for all routes, the xref:spring-cloud-gateway-server-webflux/gatewayfilter-factories/local-cache-response-filter.adoc[LocalResponseCache filter] allows to use this functionality at route level.
NOTE: To enable this feature, add `com.github.ben-manes.caffeine:caffeine` and `spring-boot-starter-cache` as project dependencies.

View File

@@ -2,7 +2,7 @@
= How to Include Spring Cloud Gateway
:page-section-summary-toc: 1
To include Spring Cloud Gateway in your project, use the starter with a group ID of `org.springframework.cloud` and an artifact ID of `spring-cloud-starter-gateway`.
To include Spring Cloud Gateway in your project, use the starter with a group ID of `org.springframework.cloud` and an artifact ID of `spring-cloud-starter-gateway-server-webflux`.
See the https://projects.spring.io/spring-cloud/[Spring Cloud Project page] for details on setting up your build system with the current Spring Cloud Release Train.
If you include the starter, but you do not want the gateway to be enabled, set `spring.cloud.gateway.enabled=false`.

View File

@@ -0,0 +1,5 @@
[[spring-cloud-gateway-server-webmvc]]
= Spring Cloud Gateway Server Web MVC
:page-section-summary-toc: 1
// TODO:

View File

@@ -155,7 +155,7 @@ In case of the request being forwarded to fallback, the Spring Cloud CircuitBrea
It is added to the `ServerRequest` as the `MvcUtils.CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR` attribute that can be used when handling the fallback within the gateway application.
For the external controller/handler scenario, headers can be added with exception details.
You can find more information on doing so in the xref:spring-cloud-gateway-server-mvc/filters/fallback-headers.adoc[FallbackHeaders Filters section].
You can find more information on doing so in the xref:spring-cloud-gateway-server-webmvc/filters/fallback-headers.adoc[FallbackHeaders Filters section].
[[circuit-breaker-status-codes]]
== Tripping The Circuit Breaker On Status Codes

View File

@@ -67,5 +67,5 @@ You can overwrite the names of the headers in the configuration by setting the v
* `rootCauseExceptionTypeHeaderName` (`"Root-Cause-Exception-Type"`)
* `rootCauseExceptionMessageHeaderName` (`"Root-Cause-Exception-Message"`)
For more information on circuit breakers and the gateway see the xref:spring-cloud-gateway-server-mvc/filters/circuitbreaker-filter.adoc[Spring Cloud CircuitBreaker Filter section].
For more information on circuit breakers and the gateway see the xref:spring-cloud-gateway-server-webmvc/filters/circuitbreaker-filter.adoc[Spring Cloud CircuitBreaker Filter section].

View File

@@ -8,7 +8,7 @@ This filter allows caching the response body and headers to follow these rules:
* Response data is not cached if `Cache-Control` header does not allow it (`no-store` present in the request or `no-store` or `private` present in the response).
* If the response is already cached and a new request is performed with no-cache value in `Cache-Control` header, it returns a bodiless response with 304 (Not Modified).
This filter configures the local response cache per route and is available only if the `spring.cloud.gateway.filter.local-response-cache.enabled` property is enabled. And a xref:spring-cloud-gateway/global-filters.adoc#local-cache-response-global-filter[local response cache configured globally] is also available as feature.
This filter configures the local response cache per route and is available only if the `spring.cloud.gateway.filter.local-response-cache.enabled` property is enabled. And a xref:spring-cloud-gateway-server-webflux/global-filters.adoc#local-cache-response-global-filter[local response cache configured globally] is also available as feature.
It accepts the first parameter to override the time to expire a cache entry (expressed in `s` for seconds, `m` for minutes, and `h` for hours) and a second parameter to set the maximum size of the cache to evict entries for this route (`KB`, `MB`, or `GB`).

View File

@@ -9,6 +9,7 @@ The `Retry` filter supports the following parameters:
* `methods`: The HTTP methods that should be retried, represented by using `org.springframework.http.HttpMethod`.
* `series`: The series of status codes to be retried, represented by using `org.springframework.http.HttpStatus.Series`.
* `exceptions`: A list of thrown exceptions that should be retried.
* `cacheBody`: A flag to signal if the request body should be cached. If set to `true`, the `adaptCacheBody` filter must be used to send the cached body downstream.
//* `backoff`: The configured exponential backoff for the retries.
//Retries are performed after a backoff interval of `firstBackoff * (factor ^ n)`, where `n` is the iteration.
//If `maxBackoff` is configured, the maximum backoff applied is limited to `maxBackoff`.
@@ -20,8 +21,11 @@ The following defaults are configured for `Retry` filter, if enabled:
* `series`: 5XX series
* `methods`: GET method
* `exceptions`: `IOException`, `TimeoutException` and `RetryException`
* `cacheBody`: `false`
//* `backoff`: disabled
WARNING: Setting `cacheBody` to `true` causes the gateway to read the whole body into memory. This should be used with caution.
The following listing configures a Retry filter:
.application.yml
@@ -42,11 +46,14 @@ spring:
retries: 3
series: SERVER_ERROR
methods: GET,POST
cacheBody: true
- name: AdaptCachedBody
----
.GatewaySampleApplication.java
[source,java]
----
import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.adaptCachedBody;
import static org.springframework.cloud.gateway.server.mvc.filter.RetryFilterFunctions.retry;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
@@ -59,7 +66,8 @@ class RouteConfiguration {
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
return route("add_request_parameter_route")
.route(host("*.retry.com"), http("https://example.org"))
.filter(retry(config -> config.setRetries(3).setSeries(Set.of(HttpStatus.Series.SERVER_ERROR)).setMethods(Set.of(HttpMethod.GET, HttpMethod.POST))))
.filter(retry(config -> config.setRetries(3).setSeries(Set.of(HttpStatus.Series.SERVER_ERROR)).setMethods(Set.of(HttpMethod.GET, HttpMethod.POST)).setCacheBody(true)))
.filter(adaptCachedBody())
.build();
}
}

Some files were not shown because too many files have changed in this diff Show More