Skip to content

Commit f649e99

Browse files
committed
Merge branch 'main' into pr/3751
2 parents a0bf89c + 43fe92f commit f649e99

File tree

51 files changed

+1548
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1548
-301
lines changed

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
*** xref:spring-cloud-gateway-server-webmvc/filters/requestsize.adoc[]
110110
*** xref:spring-cloud-gateway-server-webmvc/filters/setrequesthostheader.adoc[]
111111
*** xref:spring-cloud-gateway-server-webmvc/filters/tokenrelay.adoc[]
112+
** xref:spring-cloud-gateway-server-webmvc/httpheadersfilters.adoc[]
112113
** xref:spring-cloud-gateway-server-webmvc/writing-custom-predicates-and-filters.adoc[]
113114
** xref:spring-cloud-gateway-server-webmvc/working-with-servlets-and-filters.adoc[]
114115

docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/httpheadersfilters.adoc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
[[forwarded-headers-filter]]
77
== Forwarded Headers Filter
8-
The `Forwarded` Headers Filter creates a `Forwarded` header to send to the downstream service. It adds the `Host` header, scheme and port of the current request to any existing `Forwarded` header.
8+
The `Forwarded` Headers Filter creates a `Forwarded` header to send to the downstream service. It adds the `Host` header, scheme and port of the current request to any existing `Forwarded` header. To activate this filter set the `spring.cloud.gateway.server.webflux.trusted-proxies` property to a Java Regular Expression. This regular expression defines the proxies that are trusted when they appear in the `Forwarded` header.
99

1010
The `Forwarded by` header part can be enabled by setting the following property to true (defaults to false):
1111

12-
- `spring.cloud.gateway.forwarded.by.enabled=true`
12+
- `spring.cloud.gateway.server.webflux.forwarded.by.enabled=true`
1313

1414
[[removehopbyhop-headers-filter]]
1515
== RemoveHopByHop Headers Filter
@@ -25,25 +25,25 @@ The `RemoveHopByHop` Headers Filter removes headers from forwarded requests. The
2525
* Transfer-Encoding
2626
* Upgrade
2727

28-
To change this, set the `spring.cloud.gateway.filter.remove-hop-by-hop.headers` property to the list of header names to remove.
28+
To change this, set the `spring.cloud.gateway.server.webflux.filter.remove-hop-by-hop.headers` property to the list of header names to remove.
2929

3030
[[xforwarded-headers-filter]]
3131
== XForwarded Headers Filter
32-
The `XForwarded` Headers Filter creates various `X-Forwarded-*` headers to send to the downstream service. It uses the `Host` header, scheme, port and path of the current request to create the various headers.
32+
The `XForwarded` Headers Filter creates various `X-Forwarded-*` headers to send to the downstream service. It uses the `Host` header, scheme, port and path of the current request to create the various headers. To activate this filter set the `spring.cloud.gateway.server.webflux.trusted-proxies` property to a Java Regular Expression. This regular expression defines the proxies that are trusted when they appear in the `Forwarded` header.
3333

3434
Creating of individual headers can be controlled by the following boolean properties (defaults to true):
3535

36-
- `spring.cloud.gateway.x-forwarded.for-enabled`
37-
- `spring.cloud.gateway.x-forwarded.host-enabled`
38-
- `spring.cloud.gateway.x-forwarded.port-enabled`
39-
- `spring.cloud.gateway.x-forwarded.proto-enabled`
40-
- `spring.cloud.gateway.x-forwarded.prefix-enabled`
36+
- `spring.cloud.gateway.server.webflux.x-forwarded.for-enabled`
37+
- `spring.cloud.gateway.server.webflux.x-forwarded.host-enabled`
38+
- `spring.cloud.gateway.server.webflux.x-forwarded.port-enabled`
39+
- `spring.cloud.gateway.server.webflux.x-forwarded.proto-enabled`
40+
- `spring.cloud.gateway.server.webflux.x-forwarded.prefix-enabled`
4141

4242
Appending multiple headers can be controlled by the following boolean properties (defaults to true):
4343

44-
- `spring.cloud.gateway.x-forwarded.for-append`
45-
- `spring.cloud.gateway.x-forwarded.host-append`
46-
- `spring.cloud.gateway.x-forwarded.port-append`
47-
- `spring.cloud.gateway.x-forwarded.proto-append`
48-
- `spring.cloud.gateway.x-forwarded.prefix-append`
44+
- `spring.cloud.gateway.server.webflux.x-forwarded.for-append`
45+
- `spring.cloud.gateway.server.webflux.x-forwarded.host-append`
46+
- `spring.cloud.gateway.server.webflux.x-forwarded.port-append`
47+
- `spring.cloud.gateway.server.webflux.x-forwarded.proto-append`
48+
- `spring.cloud.gateway.server.webflux.x-forwarded.prefix-append`
4949

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[[httpheadersfilters]]
2+
= HttpHeadersFilters
3+
4+
HttpHeadersFilters are applied to the requests before sending them downstream, such as in the `NettyRoutingFilter`.
5+
6+
[[forwarded-headers-filter]]
7+
== Forwarded Headers Filter
8+
The `Forwarded` Headers Filter creates a `Forwarded` header to send to the downstream service. It adds the `Host` header, scheme and port of the current request to any existing `Forwarded` header. To activate this filter set the `spring.cloud.gateway.server.webmvc.trusted-proxies` property to a Java Regular Expression. This regular expression defines the proxies that are trusted when they appear in the `Forwarded` header.
9+
10+
[[removehopbyhop-headers-filter]]
11+
== RemoveHopByHop Headers Filter
12+
The `RemoveHopByHop` Headers Filter removes headers from forwarded requests. The default list of headers that is removed comes from the https://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-14#section-7.1.3[IETF].
13+
14+
.The default removed headers are:
15+
* Connection
16+
* Keep-Alive
17+
* Proxy-Authenticate
18+
* Proxy-Authorization
19+
* TE
20+
* Trailer
21+
* Transfer-Encoding
22+
* Upgrade
23+
24+
//To change this, set the `spring.cloud.gateway.filter.remove-hop-by-hop.headers` property to the list of header names to remove.
25+
26+
[[xforwarded-headers-filter]]
27+
== XForwarded Headers Filter
28+
The `XForwarded` Headers Filter creates various `X-Forwarded-*` headers to send to the downstream service. It uses the `Host` header, scheme, port and path of the current request to create the various headers. To activate this filter set the `spring.cloud.gateway.server.webmvc.trusted-proxies` property to a Java Regular Expression. This regular expression defines the proxies that are trusted when they appear in the `Forwarded` header.
29+
30+
Creating of individual headers can be controlled by the following boolean properties (defaults to true):
31+
32+
- `spring.cloud.gateway.server.webmvc.x-forwarded.for-enabled`
33+
- `spring.cloud.gateway.server.webmvc.x-forwarded.host-enabled`
34+
- `spring.cloud.gateway.server.webmvc.x-forwarded.port-enabled`
35+
- `spring.cloud.gateway.server.webmvc.x-forwarded.proto-enabled`
36+
- `spring.cloud.gateway.server.webmvc.x-forwarded.prefix-enabled`
37+
38+
Appending multiple headers can be controlled by the following boolean properties (defaults to true):
39+
40+
- `spring.cloud.gateway.server.webmvc.x-forwarded.for-append`
41+
- `spring.cloud.gateway.server.webmvc.x-forwarded.host-append`
42+
- `spring.cloud.gateway.server.webmvc.x-forwarded.port-append`
43+
- `spring.cloud.gateway.server.webmvc.x-forwarded.proto-append`
44+
- `spring.cloud.gateway.server.webmvc.x-forwarded.prefix-append`
45+

docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/java-routes-api.adoc

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,71 @@ class SimpleGateway {
4949
[[gateway-handlerfunctions]]
5050
== Gateway MVC Handler Functions
5151

52-
Various `RouterFunctions.Builder` methods require a `HandlerFunction<ServerResponse>`. To create a route that is proxied by the MVC Gateway, `HandlerFunction` implementations are supplied in `org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions`. The most basic is the `http()` `HandlerFunction`. The function looks for a `URI` in the `org.springframework.cloud.gateway.server.mvc.common.MvcUtils.GATEWAY_REQUEST_URL_ATTR` request attribute. This allows for dynamic targets such as load balancing to set the `URI`.
5352

54-
WARNING: As of version 4.1.7, `HandlerFunctions.http(String)` and `HandlerFunctions.http(URI)` are now deprecated. Please use `HandlerFunctions.http()` in combination with the `BeforeFilterFunctions.uri()` filter instead. This fixes inconsistencies in dealing with the route url request attribute.
53+
Various `RouterFunctions.Builder` methods require a `HandlerFunction<ServerResponse>`. To create a route that is proxied by the MVC Gateway, `HandlerFunction` implementations are supplied in `org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions`.
54+
55+
=== HTTP Handler Function
56+
The most basic handler function is `http()` `HandlerFunction`. If a `URI` is supplied as a parameter, that is the `URI` used as the downstream target for sending the HTTP requests (as seen in the example above). If no parameter is passed, the function looks for a `URI` in the `org.springframework.cloud.gateway.server.mvc.common.MvcUtils.GATEWAY_REQUEST_URL_ATTR` request attribute. This allows for dynamic targets such as load balancing to set the `URI`.
57+
58+
59+
WARNING: As of version 4.1.7, `HandlerFunctions.http(String)` and `HandlerFunctions.http(URI)` are now deprecated. Please use `HandlerFunctions.http()` in combination with the `BeforeFilterFunctions.uri()` filter instead. This fixes inconsistencies in dealing with the route url request attribute.
60+
61+
=== Spring Cloud Function Handler Function
62+
By placing https://spring.io/projects/spring-cloud-function[Spring Cloud Function] on the classpath, Spring Cloud Gateway will automatically configure routes to invoke functions you define as beans. The bean names of the functions will be used as the path of the routes.
63+
64+
For example, given the following configuration:
65+
66+
[source,xml]
67+
----
68+
<dependency>
69+
<groupId>org.springframework.cloud</groupId>
70+
<artifactId>spring-cloud-function-context</artifactId>
71+
</dependency>
72+
----
73+
74+
Once Spring Cloud Function dependency is provided the name of the Java function bean becomes the path you can use to route to functions.
75+
76+
For example, assume the following application:
77+
78+
[source,java]
79+
----
80+
@SpringBootApplication
81+
public class DemoFunctionGatewayApplication {
82+
83+
public static void main(String[] args) {
84+
SpringApplication.run(DemoFunctionGatewayApplication.class, args);
85+
}
86+
87+
88+
@Bean
89+
public Function<String, String> uppercase() {
90+
return v -> v.toUpperCase();
91+
}
92+
93+
@Bean
94+
public Function<String, String> concat() {
95+
return v -> v + v;
96+
}
97+
}
98+
----
99+
You can invoke the `concat` or `uppercase` functions by issuing a `GET` or `POST` request to `/concat` or `/uppercase`.
100+
101+
Making a `GET` request to ``http://localhost:8080/uppercase/hello` will invoke the `uppercase` function with the String `hello` and return `HELLO` in the `GET` response body.
102+
103+
Instead of passing the function parameter as a path parameter you can use a `POST` request. For example the following cURL command can issued to invoke the `concat` function:
104+
105+
[source,bash]
106+
----
107+
$ curl -d ‘"hello"' -H "Content-Type: application/json" -X POST http://localhost:8080/concat
108+
----
109+
110+
The response body will contain `hellohello`.
111+
112+
Spring Cloud Gateway also supports function composition by issuing a request to a path composed of function names separated by a comma. For example:
113+
114+
[source,bash]
115+
----
116+
$ curl -d ‘"hello"' -H "Content-Type: application/json" -X POST http://localhost:8080/concat,uppercase
117+
----
118+
119+
The response body will contain `HELLOHELLO`.

0 commit comments

Comments
 (0)