Dedupe response header filter (#866)

Filter that de-duplicates response filter values. Comes handy when e.g. both the gateway CORS logic and a downstream add Access-Control-Allow-Credentials and Access-Control-Allow-Origin headers. See https://github.com/spring-cloud/spring-cloud-gateway/issues/728 for additional context.
This commit is contained in:
vpavlyuk
2019-03-20 16:00:50 -04:00
committed by Spencer Gibb
parent 9c00e60ee4
commit 0beff09af2
8 changed files with 380 additions and 1 deletions

View File

@@ -369,7 +369,7 @@ spring:
cloud:
gateway:
routes:
- id: add_request_header_route
- id: add_response_header_route
uri: http://example.org
filters:
- AddResponseHeader=X-Response-Foo, Bar
@@ -377,6 +377,26 @@ spring:
This will add `X-Response-Foo:Bar` header to the downstream response's headers for all matching requests.
=== DedupeResponseHeader GatewayFilter Factory
The DedupeResponseHeader GatewayFilter Factory takes a `name` parameter and an optional `strategy` parameter. `name` can contain a list of header names, space separated.
.application.yml
[source,yaml]
----
spring:
cloud:
gateway:
routes:
- id: dedupe_response_header_route
uri: http://example.org
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
----
This will remove 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 add them.
The DedupeResponseHeader filter also accepts an optional `strategy` parameter. The accepted values are `RETAIN_FIRST` (default), `RETAIN_LAST`, and `RETAIN_UNIQUE`.
=== Hystrix GatewayFilter Factory
https://github.com/Netflix/Hystrix[Hystrix] is a library from Netflix that implements the https://martinfowler.com/bliki/CircuitBreaker.html[circuit breaker pattern].
The Hystrix GatewayFilter allows you to introduce circuit breakers to your gateway routes, protecting your services from cascading failures and allowing you to provide fallback responses in the event of downstream failures.