Skip to content

Commit ff98d62

Browse files
committed
Initial documentation.
Includes general documentation and most filters. TODO: request predicates and custome dev docs.
1 parent da19814 commit ff98d62

40 files changed

+2104
-1
lines changed

docs/modules/ROOT/nav.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,44 @@
7070
** xref:spring-cloud-gateway-server-mvc/glossary.adoc[]
7171
** xref:spring-cloud-gateway-server-mvc/how-it-works.adoc[]
7272
** xref:spring-cloud-gateway-server-mvc/java-routes-api.adoc[]
73+
** xref:spring-cloud-gateway-server-mvc/gateway-request-predicates.adoc[]
74+
** xref:spring-cloud-gateway-server-mvc/gateway-handler-filter-functions.adoc[]
75+
*** xref:spring-cloud-gateway-server-mvc/filters/addrequestheader.adoc[]
76+
*** xref:spring-cloud-gateway-server-mvc/filters/addrequestheadersifnotpresent.adoc[]
77+
*** xref:spring-cloud-gateway-server-mvc/filters/addrequestparameter.adoc[]
78+
*** xref:spring-cloud-gateway-server-mvc/filters/addresponseheader.adoc[]
79+
*** xref:spring-cloud-gateway-server-mvc/filters/circuitbreaker-filter.adoc[]
80+
*** xref:spring-cloud-gateway-server-mvc/filters/deduperesponseheader.adoc[]
81+
*** xref:spring-cloud-gateway-server-mvc/filters/fallback-headers.adoc[]
82+
//*** xref:spring-cloud-gateway-server-mvc/filters/local-cache-response-filter.adoc[]
83+
*** xref:spring-cloud-gateway-server-mvc/filters/maprequestheader.adoc[]
84+
*** xref:spring-cloud-gateway-server-mvc/filters/modifyrequestbody.adoc[]
85+
//*** xref:spring-cloud-gateway-server-mvc/filters/modifyresponsebody.adoc[]
86+
*** xref:spring-cloud-gateway-server-mvc/filters/prefixpath.adoc[]
87+
*** xref:spring-cloud-gateway-server-mvc/filters/preservehostheader.adoc[]
88+
*** xref:spring-cloud-gateway-server-mvc/filters/redirectto.adoc[]
89+
//*** xref:spring-cloud-gateway-server-mvc/filters/removejsonattributesresponsebody.adoc[]
90+
*** xref:spring-cloud-gateway-server-mvc/filters/removerequestheader.adoc[]
91+
*** xref:spring-cloud-gateway-server-mvc/filters/removerequestparameter.adoc[]
92+
*** xref:spring-cloud-gateway-server-mvc/filters/removeresponseheader.adoc[]
93+
*** xref:spring-cloud-gateway-server-mvc/filters/requestheadersize.adoc[]
94+
*** xref:spring-cloud-gateway-server-mvc/filters/requestratelimiter.adoc[]
95+
*** xref:spring-cloud-gateway-server-mvc/filters/rewritelocationresponseheader.adoc[]
96+
*** xref:spring-cloud-gateway-server-mvc/filters/rewritepath.adoc[]
97+
//*** xref:spring-cloud-gateway-server-mvc/filters/rewriterequestparameter.adoc[]
98+
*** xref:spring-cloud-gateway-server-mvc/filters/rewriteresponseheader.adoc[]
99+
//*** xref:spring-cloud-gateway-server-mvc/filters/savesession.adoc[]
100+
//*** xref:spring-cloud-gateway-server-mvc/filters/secureheaders.adoc[]
101+
*** xref:spring-cloud-gateway-server-mvc/filters/setpath.adoc[]
102+
*** xref:spring-cloud-gateway-server-mvc/filters/setrequestheader.adoc[]
103+
*** xref:spring-cloud-gateway-server-mvc/filters/setresponseheader.adoc[]
104+
*** xref:spring-cloud-gateway-server-mvc/filters/setstatus.adoc[]
105+
*** xref:spring-cloud-gateway-server-mvc/filters/stripprefix.adoc[]
106+
*** xref:spring-cloud-gateway-server-mvc/filters/retry.adoc[]
107+
*** xref:spring-cloud-gateway-server-mvc/filters/requestsize.adoc[]
108+
*** xref:spring-cloud-gateway-server-mvc/filters/setrequesthostheader.adoc[]
109+
*** xref:spring-cloud-gateway-server-mvc/filters/tokenrelay.adoc[]
110+
** xref:spring-cloud-gateway-server-mvc/writing-custom-predicates-and-filters.adoc[]
73111
74112
// begin Gateway Proxy Exchange
75113
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[[addrequestheader-filter]]
2+
= `AddRequestHeader` Filter
3+
4+
The `AddRequestHeader` is a "before" filter that takes a `name` and `value` parameter.
5+
The following example configures an `AddRequestHeader` filter:
6+
7+
.GatewaySampleApplication.java
8+
[source,java]
9+
----
10+
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.addRequestHeader;
11+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
12+
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
13+
14+
@Configuration
15+
class RouteConfiguration {
16+
17+
@Bean
18+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
19+
return route(GET("/red"), http("https://example.org"))
20+
.before(addRequestHeader("X-Request-red", "blue"));
21+
}
22+
}
23+
----
24+
25+
This listing adds `X-Request-red:blue` header to the downstream request's headers for all matching requests.
26+
27+
`AddRequestHeader` is aware of the URI variables used to match a path or host.
28+
URI variables may be used in the value and are expanded at runtime.
29+
The following example configures an `AddRequestHeader` filter that uses a variable:
30+
31+
.GatewaySampleApplication.java
32+
[source,java]
33+
----
34+
@Configuration
35+
class RouteConfiguration {
36+
37+
@Bean
38+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
39+
return route(GET("/red/{segment}"), http("https://example.org"))
40+
.before(addRequestHeader("X-Request-red", "blue-{segment}"));
41+
}
42+
}
43+
----
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[[addrequestheadersifnotpresent-filter]]
2+
= `AddRequestHeadersIfNotPresent` Filter
3+
4+
The `AddRequestHeadersIfNotPresent` filter takes a collection of `name` and `value` pairs separated by colon.
5+
The following example configures an `AddRequestHeadersIfNotPresent` filter:
6+
7+
.GatewaySampleApplication.java
8+
[source,java]
9+
----
10+
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.addRequestHeadersIfNotPresent;
11+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
12+
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
13+
14+
@Configuration
15+
class RouteConfiguration {
16+
17+
@Bean
18+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
19+
return route(GET("/red"), http("https://example.org"))
20+
.before(addRequestHeadersIfNotPresent("X-Request-Color-1:blue","X-Request-Color-2:green"));
21+
}
22+
}
23+
----
24+
25+
This listing adds 2 headers `X-Request-Color-1:blue` and `X-Request-Color-2:green` to the downstream request's headers for all matching requests.
26+
This is similar to how `AddRequestHeader` works, but unlike `AddRequestHeader` it will do it only if the header is not already there.
27+
Otherwise, the original value in the client request is sent.
28+
29+
Additionally, to set a multi-valued header, use the header name multiple times like `addRequestHeadersIfNotPresent("X-Request-Color-1:blue","X-Request-Color-1:green")`.
30+
31+
`AddRequestHeadersIfNotPresent` also supports URI variables used to match a path or host.
32+
URI variables may be used in the value and are expanded at runtime.
33+
The following example configures an `AddRequestHeadersIfNotPresent` filter that uses a variable:
34+
35+
.GatewaySampleApplication.java
36+
[source,java]
37+
----
38+
@Configuration
39+
class RouteConfiguration {
40+
41+
@Bean
42+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
43+
return route(GET("/red/{segment}"), http("https://example.org"))
44+
.before(addRequestHeadersIfNotPresent("X-Request-red", "blue-{segment}"));
45+
}
46+
}
47+
----
48+
.application.yml
49+
[source,yaml]
50+
----
51+
spring:
52+
cloud:
53+
gateway:
54+
routes:
55+
- id: add_request_header_route
56+
uri: https://example.org
57+
predicates:
58+
- Path=/red/{segment}
59+
filters:
60+
- AddRequestHeadersIfNotPresent=X-Request-Red:Blue-{segment}
61+
----
62+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[[addrequestparameter-filter]]
2+
= `AddRequestParameter` Filter
3+
4+
The `AddRequestParameter` Filter takes a `name` and `value` parameter.
5+
The following example configures an `AddRequestParameter` filter:
6+
7+
.GatewaySampleApplication.java
8+
[source,java]
9+
----
10+
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.addRequestParameter;
11+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
12+
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
13+
14+
@Configuration
15+
class RouteConfiguration {
16+
17+
@Bean
18+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
19+
return route("add_request_parameter_route")
20+
.GET("/anything/addrequestparam", http("https://example.org"))
21+
.before(addRequestParameter("red", "blue"))
22+
.build();
23+
}
24+
}
25+
----
26+
27+
This will add `red=blue` to the downstream request's query string for all matching requests.
28+
29+
`AddRequestParameter` is aware of the URI variables used to match a path or host.
30+
URI variables may be used in the value and are expanded at runtime.
31+
The following example configures an `AddRequestParameter` filter that uses a variable:
32+
33+
.GatewaySampleApplication.java
34+
[source,java]
35+
----
36+
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.addRequestParameter;
37+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
38+
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
39+
import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.host;
40+
41+
@Configuration
42+
class RouteConfiguration {
43+
44+
@Bean
45+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddReqHeader() {
46+
return route("add_request_parameter_route")
47+
.route(host("{segment}.myhost.org"), http("https://example.org"))
48+
.before(addRequestParameter("foo", "bar-{segment}"))
49+
.build();
50+
}
51+
}
52+
----
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[[addresponseheader-filter]]
2+
= `AddResponseHeader` Filter
3+
4+
The `AddResponseHeader` Filter takes a `name` and `value` parameter.
5+
The following example configures an `AddResponseHeader` filter:
6+
7+
.GatewaySampleApplication.java
8+
[source,java]
9+
----
10+
import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.addResponseHeader;
11+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
12+
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
13+
14+
@Configuration
15+
class RouteConfiguration {
16+
17+
@Bean
18+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddRespHeader() {
19+
return route("addresponseheader")
20+
.GET("/anything/addresheader", http("https://example.org"))
21+
.after(addResponseHeader("X-Response-Red", "Blue"))
22+
.build();
23+
}
24+
}
25+
----
26+
27+
This adds `X-Response-Red:Blue` header to the downstream response's headers for all matching requests.
28+
29+
`AddResponseHeader` is aware of URI variables used to match a path or host.
30+
URI variables may be used in the value and are expanded at runtime.
31+
The following example configures an `AddResponseHeader` filter that uses a variable:
32+
33+
.GatewaySampleApplication.java
34+
[source,java]
35+
----
36+
import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.addResponseHeader;
37+
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
38+
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
39+
import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.host;
40+
41+
@Configuration
42+
class RouteConfiguration {
43+
44+
@Bean
45+
public RouterFunction<ServerResponse> gatewayRouterFunctionsAddRespHeader() {
46+
return route("add_response_header_route")
47+
.route(host("{segment}.myhost.org"), http("https://example.org"))
48+
.after(addResponseHeader("foo", "bar-{segment}"))
49+
.build();
50+
}
51+
}
52+
----
53+

0 commit comments

Comments
 (0)