@@ -150,20 +150,38 @@ public CorsProcessor getCorsProcessor() {
150
150
}
151
151
152
152
153
- protected Object processCorsRequest (ServerWebExchange exchange , Object handler ) {
154
- if (CorsUtils .isCorsRequest (exchange .getRequest ())) {
155
- CorsConfiguration configA = this .globalCorsConfigSource .getCorsConfiguration (exchange );
156
- CorsConfiguration configB = getCorsConfiguration (handler , exchange );
157
- CorsConfiguration config = (configA != null ? configA .combine (configB ) : configB );
158
-
159
- if (!getCorsProcessor ().processRequest (config , exchange ) ||
160
- CorsUtils .isPreFlightRequest (exchange .getRequest ())) {
161
- return REQUEST_HANDLED_HANDLER ;
153
+ @ Override
154
+ public Mono <Object > getHandler (ServerWebExchange exchange ) {
155
+ return getHandlerInternal (exchange ).map (handler -> {
156
+ if (CorsUtils .isCorsRequest (exchange .getRequest ())) {
157
+ CorsConfiguration configA = this .globalCorsConfigSource .getCorsConfiguration (exchange );
158
+ CorsConfiguration configB = getCorsConfiguration (handler , exchange );
159
+ CorsConfiguration config = (configA != null ? configA .combine (configB ) : configB );
160
+
161
+ if (!getCorsProcessor ().processRequest (config , exchange ) ||
162
+ CorsUtils .isPreFlightRequest (exchange .getRequest ())) {
163
+ return REQUEST_HANDLED_HANDLER ;
164
+ }
162
165
}
163
- }
164
- return handler ;
166
+ return handler ;
167
+ }) ;
165
168
}
166
169
170
+ /**
171
+ * Look up a handler for the given request, returning an empty {@code Mono}
172
+ * if no specific one is found. This method is called by {@link #getHandler}.
173
+ *
174
+ * <p>On CORS pre-flight requests this method should return a match not for
175
+ * the pre-flight request but for the expected actual request based on the URL
176
+ * path, the HTTP methods from the "Access-Control-Request-Method" header, and
177
+ * the headers from the "Access-Control-Request-Headers" header thus allowing
178
+ * the CORS configuration to be obtained via {@link #getCorsConfigurations},
179
+ *
180
+ * @param exchange current exchange
181
+ * @return {@code Mono} for the matching handler, if any
182
+ */
183
+ protected abstract Mono <?> getHandlerInternal (ServerWebExchange exchange );
184
+
167
185
/**
168
186
* Retrieve the CORS configuration for the given handler.
169
187
* @param handler the handler to check (never {@code null}).
0 commit comments