Class CorsWebFilter
- java.lang.Object
- org.springframework.web.cors.reactive.CorsWebFilter
- All Implemented Interfaces:
WebFilter
public class CorsWebFilter extends Object implements WebFilter
WebFilter
that handles CORS preflight requests and intercepts CORS simple and actual requests thanks to aCorsProcessor
implementation (DefaultCorsProcessor
by default) in order to add the relevant CORS response headers (likeAccess-Control-Allow-Origin
) using the providedCorsConfigurationSource
(for example anUrlBasedCorsConfigurationSource
instance.This is an alternative to Spring WebFlux Java config CORS configuration, mostly useful for applications using the functional API.
- Since:
- 5.0
- Author:
- Sebastien Deleuze
- See Also:
- CORS W3C recommendation
Constructor Summary
Constructors Constructor Description CorsWebFilter(CorsConfigurationSource configSource)
Constructor accepting aCorsConfigurationSource
used by the filter to find theCorsConfiguration
to use for each incoming request.CorsWebFilter(CorsConfigurationSource configSource, CorsProcessor processor)
Constructor accepting aCorsConfigurationSource
used by the filter to find theCorsConfiguration
to use for each incoming request and a customCorsProcessor
to use to apply the matchedCorsConfiguration
for a request.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description reactor.core.publisher.Mono<Void>
filter(ServerWebExchange exchange, WebFilterChain chain)
Process the Web request and (optionally) delegate to the nextWebFilter
through the givenWebFilterChain
.
Constructor Detail
CorsWebFilter
public CorsWebFilter(CorsConfigurationSource configSource)
Constructor accepting aCorsConfigurationSource
used by the filter to find theCorsConfiguration
to use for each incoming request.- See Also:
UrlBasedCorsConfigurationSource
CorsWebFilter
public CorsWebFilter(CorsConfigurationSource configSource, CorsProcessor processor)
Constructor accepting aCorsConfigurationSource
used by the filter to find theCorsConfiguration
to use for each incoming request and a customCorsProcessor
to use to apply the matchedCorsConfiguration
for a request.- See Also:
UrlBasedCorsConfigurationSource
Method Detail
filter
public reactor.core.publisher.Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain)
Description copied from interface:WebFilter
Process the Web request and (optionally) delegate to the nextWebFilter
through the givenWebFilterChain
.