Add getHandler in reactive AbstractHandlerMapping
This commit is contained in:
@@ -469,7 +469,7 @@ public class WebReactiveConfiguration implements ApplicationContextAware {
|
||||
private static final class EmptyHandlerMapping extends AbstractHandlerMapping {
|
||||
|
||||
@Override
|
||||
public Mono<Object> getHandler(ServerWebExchange exchange) {
|
||||
public Mono<Object> getHandlerInternal(ServerWebExchange exchange) {
|
||||
return Mono.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,20 +150,38 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
|
||||
}
|
||||
|
||||
|
||||
protected Object processCorsRequest(ServerWebExchange exchange, Object handler) {
|
||||
if (CorsUtils.isCorsRequest(exchange.getRequest())) {
|
||||
CorsConfiguration configA = this.globalCorsConfigSource.getCorsConfiguration(exchange);
|
||||
CorsConfiguration configB = getCorsConfiguration(handler, exchange);
|
||||
CorsConfiguration config = (configA != null ? configA.combine(configB) : configB);
|
||||
@Override
|
||||
public Mono<Object> getHandler(ServerWebExchange exchange) {
|
||||
return getHandlerInternal(exchange).map(handler -> {
|
||||
if (CorsUtils.isCorsRequest(exchange.getRequest())) {
|
||||
CorsConfiguration configA = this.globalCorsConfigSource.getCorsConfiguration(exchange);
|
||||
CorsConfiguration configB = getCorsConfiguration(handler, exchange);
|
||||
CorsConfiguration config = (configA != null ? configA.combine(configB) : configB);
|
||||
|
||||
if (!getCorsProcessor().processRequest(config, exchange) ||
|
||||
CorsUtils.isPreFlightRequest(exchange.getRequest())) {
|
||||
return REQUEST_HANDLED_HANDLER;
|
||||
if (!getCorsProcessor().processRequest(config, exchange) ||
|
||||
CorsUtils.isPreFlightRequest(exchange.getRequest())) {
|
||||
return REQUEST_HANDLED_HANDLER;
|
||||
}
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
return handler;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a handler for the given request, returning an empty {@code Mono}
|
||||
* if no specific one is found. This method is called by {@link #getHandler}.
|
||||
*
|
||||
* <p>On CORS pre-flight requests this method should return a match not for
|
||||
* the pre-flight request but for the expected actual request based on the URL
|
||||
* path, the HTTP methods from the "Access-Control-Request-Method" header, and
|
||||
* the headers from the "Access-Control-Request-Headers" header thus allowing
|
||||
* the CORS configuration to be obtained via {@link #getCorsConfigurations},
|
||||
*
|
||||
* @param exchange current exchange
|
||||
* @return {@code Mono} for the matching handler, if any
|
||||
*/
|
||||
protected abstract Mono<?> getHandlerInternal(ServerWebExchange exchange);
|
||||
|
||||
/**
|
||||
* Retrieve the CORS configuration for the given handler.
|
||||
* @param handler the handler to check (never {@code null}).
|
||||
|
||||
@@ -96,12 +96,11 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<Object> getHandler(ServerWebExchange exchange) {
|
||||
public Mono<Object> getHandlerInternal(ServerWebExchange exchange) {
|
||||
String lookupPath = getPathHelper().getLookupPathForRequest(exchange);
|
||||
Object handler;
|
||||
try {
|
||||
handler = lookupHandler(lookupPath, exchange);
|
||||
handler = processCorsRequest(exchange, handler);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
|
||||
@@ -254,7 +254,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
* @param exchange the current exchange
|
||||
*/
|
||||
@Override
|
||||
public Mono<Object> getHandler(ServerWebExchange exchange) {
|
||||
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
|
||||
String lookupPath = getPathHelper().getLookupPathForRequest(exchange);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Looking up handler method for path " + lookupPath);
|
||||
@@ -279,7 +279,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
if (handlerMethod != null) {
|
||||
handlerMethod = handlerMethod.createWithResolvedBean();
|
||||
}
|
||||
return Mono.justOrEmpty(processCorsRequest(exchange, handlerMethod));
|
||||
return Mono.justOrEmpty(handlerMethod);
|
||||
}
|
||||
finally {
|
||||
this.mappingRegistry.releaseReadLock();
|
||||
|
||||
Reference in New Issue
Block a user