You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -489,7 +489,7 @@ Route filters allow the modification of the incoming HTTP request or outgoing HT
489
489
Route filters are scoped to a particular route.
490
490
Spring Cloud Gateway includes many built-in GatewayFilter Factories.
491
491
492
-
NOTE: For more detailed examples of how to use any of the following filters, take a look at the https://github.com/spring-cloud/spring-cloud-gateway/tree/master/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory[unit tests].
492
+
NOTE: For more detailed examples of how to use any of the following filters, take a look at the https://github.com/spring-cloud/spring-cloud-gateway/tree/3.1.x/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory[unit tests].
493
493
494
494
=== The `AddRequestHeader` `GatewayFilter` Factory
495
495
@@ -620,31 +620,6 @@ spring:
620
620
----
621
621
====
622
622
623
-
=== The `DedupeResponseHeader` `GatewayFilter` Factory
624
-
625
-
The DedupeResponseHeader GatewayFilter factory takes a `name` parameter and an optional `strategy` parameter. `name` can contain a space-separated list of header names.
626
-
The following example configures a `DedupeResponseHeader` `GatewayFilter`:
This removes duplicate values of `Access-Control-Allow-Credentials` and `Access-Control-Allow-Origin` response headers in cases when both the gateway CORS logic and the downstream logic add them.
644
-
645
-
The `DedupeResponseHeader` filter also accepts an optional `strategy` parameter.
646
-
The accepted values are `RETAIN_FIRST` (default), `RETAIN_LAST`, and `RETAIN_UNIQUE`.
647
-
648
623
[[spring-cloud-circuitbreaker-filter-factory]]
649
624
=== Spring Cloud CircuitBreaker GatewayFilter Factory
650
625
@@ -802,6 +777,30 @@ public RouteLocator routes(RouteLocatorBuilder builder) {
802
777
----
803
778
====
804
779
780
+
=== The `DedupeResponseHeader` `GatewayFilter` Factory
781
+
782
+
The `DedupeResponseHeader` GatewayFilter factory takes a `name` parameter and an optional `strategy` parameter. `name` can contain a space-separated list of header names.
783
+
The following example configures a `DedupeResponseHeader` `GatewayFilter`:
This removes duplicate values of `Access-Control-Allow-Credentials` and `Access-Control-Allow-Origin` response headers in cases when both the gateway CORS logic and the downstream logic add them.
801
+
802
+
The `DedupeResponseHeader` filter also accepts an optional `strategy` parameter.
803
+
The accepted values are `RETAIN_FIRST` (default), `RETAIN_LAST`, and `RETAIN_UNIQUE`.
805
804
806
805
807
806
[[fallback-headers]]
@@ -849,6 +848,142 @@ You can overwrite the names of the headers in the configuration by setting the v
849
848
850
849
For more information on circuit breakers and the gateway see the <<spring-cloud-circuitbreaker-filter-factory, Spring Cloud CircuitBreaker Factory section>>.
851
850
851
+
=== The `JsonToGrpc` `GatewayFilter` Factory
852
+
853
+
The JSONToGRPCFilter GatewayFilter Factory converts a JSON payload to a gRPC request.
854
+
855
+
The filter takes the following arguments:
856
+
857
+
* `protoDescriptor`: Proto descriptor file.
858
+
859
+
This file can be generated using `protoc` and specifying the `--descriptor_set_out` flag:
When a request is made through the gateway to `/json/hello`, the request is transformed by using the definition provided in `hello.proto`, sent to `HelloService/hello`, and the response back is transformed to JSON.
914
+
915
+
By default, it creates a `NettyChannel` by using the default `TrustManagerFactory`. However, you can customize this `TrustManager` by creating a bean of type `GrpcSslConfigurer`:
916
+
917
+
[source,java]
918
+
----
919
+
920
+
@Configuration
921
+
public class GRPCLocalConfiguration {
922
+
@Bean
923
+
public GRPCSSLContext sslContext() {
924
+
TrustManager trustManager = trustAllCerts();
925
+
return new GRPCSSLContext(trustManager);
926
+
}
927
+
}
928
+
----
929
+
930
+
[[local-cache-response-filter]]
931
+
=== The `LocalResponseCache` `GatewayFilter` Factory
932
+
933
+
This filter allows caching the response body and headers to follow these rules:
934
+
935
+
* It can only cache bodiless GET requests.
936
+
* It caches the response only for one of the following status codes: HTTP 200 (OK), HTTP 206 (Partial Content), or HTTP 301 (Moved Permanently).
937
+
* 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).
938
+
* 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).
939
+
940
+
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 <<local-cache-response-global-filter, local response cache configured globally>> is also available as feature.
941
+
942
+
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`).
943
+
944
+
The following listing shows how to add local response cache `GatewayFilter`:
945
+
946
+
====
947
+
[source,java]
948
+
----
949
+
@Bean
950
+
public RouteLocator routes(RouteLocatorBuilder builder) {
951
+
return builder.routes()
952
+
.route("rewrite_response_upper", r -> r.host("*.rewriteresponseupper.org")
NOTE: This filter also automatically calculates the `max-age` value in the HTTP `Cache-Control` header.
979
+
Only if `max-age` is present on the original response is the value rewritten with the number of seconds set in the `timeToLive` configuration parameter.
980
+
In consecutive calls, this value is recalculated with the number of seconds left until the response expires.
981
+
982
+
NOTE: To enable this feature, add `com.github.ben-manes.caffeine:caffeine` and `spring-boot-starter-cache` as project dependencies.
983
+
984
+
WARNING: If your project creates custom `CacheManager` beans, it will either need to be marked with `@Primary` or injected using `@Qualifier`.
985
+
986
+
852
987
=== The `MapRequestHeader` `GatewayFilter` Factory
853
988
854
989
The `MapRequestHeader` `GatewayFilter` factory takes `fromHeader` and `toHeader` parameters.
@@ -872,7 +1007,77 @@ spring:
872
1007
----
873
1008
====
874
1009
875
-
This adds `X-Request-Red:<values>` header to the downstream request with updated values from the incoming HTTP request's `Blue` header.
1010
+
This adds the `X-Request-Red:<values>` header to the downstream request with updated values from the incoming HTTP request's `Blue` header.
1011
+
1012
+
=== The `ModifyRequestBody` `GatewayFilter` Factory
1013
+
1014
+
You can use the `ModifyRequestBody` filter to modify the request body before it is sent downstream by the gateway.
1015
+
1016
+
NOTE: This filter can be configured only by using the Java DSL.
1017
+
1018
+
The following listing shows how to modify a request body `GatewayFilter`:
1019
+
1020
+
====
1021
+
[source,java]
1022
+
----
1023
+
@Bean
1024
+
public RouteLocator routes(RouteLocatorBuilder builder) {
1025
+
return builder.routes()
1026
+
.route("rewrite_request_obj", r -> r.host("*.rewriterequestobj.org")
=== The `RemoveResponseHeader` `GatewayFilter` Factory
1098
1303
1099
1304
The `RemoveResponseHeader` `GatewayFilter` factory takes a `name` parameter.
1100
1305
It is the name of the header to be removed.
@@ -2100,7 +2305,7 @@ or check if an exchange has already been routed.
2100
2305
HttpHeadersFilters are applied to requests before sending them downstream, such as in the `NettyRoutingFilter`.
2101
2306
2102
2307
=== Forwarded Headers Filter
2103
-
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.
2308
+
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.trusted-proxies` property to a Java Regular Expression. This regular expression defines the proxies that are trusted when they appear in the `Forwarded` header.
2104
2309
2105
2310
=== RemoveHopByHop Headers Filter
2106
2311
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].
@@ -2118,7 +2323,7 @@ The `RemoveHopByHop` Headers Filter removes headers from forwarded requests. The
2118
2323
To change this, set the `spring.cloud.gateway.filter.remove-hop-by-hop.headers` property to the list of header names to remove.
2119
2324
2120
2325
=== XForwarded Headers Filter
2121
-
The `XForwarded` Headers Filter creates various a `X-Forwarded-*` headers to send to the downstream service. It users the `Host` header, scheme, port and path of the current request to create the various headers.
2326
+
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.trusted-proxies` property to a Java Regular Expression. This regular expression defines the proxies that are trusted when they appear in the `X-Forwarded-For` header.
2122
2327
2123
2328
Creating of individual headers can be controlled by the following boolean properties (defaults to true):
0 commit comments