org.springframework.web.cors.CorsProcessor Maven / Gradle / Ivy
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.cors;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.lang.Nullable;
/**
* A strategy that takes a request and a {@link CorsConfiguration} and updates
* the response.
*
* This component is not concerned with how a {@code CorsConfiguration} is
* selected but rather takes follow-up actions such as applying CORS validation
* checks and either rejecting the response or adding CORS headers to the
* response.
*
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
* @since 4.2
* @see CORS W3C recommendation
* @see org.springframework.web.servlet.handler.AbstractHandlerMapping#setCorsProcessor
*/
public interface CorsProcessor {
/**
* Process a request given a {@code CorsConfiguration}.
* @param configuration the applicable CORS configuration (possibly {@code null})
* @param request the current request
* @param response the current response
* @return {@code false} if the request is rejected, {@code true} otherwise
*/
boolean processRequest(@Nullable CorsConfiguration configuration, HttpServletRequest request,
HttpServletResponse response) throws IOException;
}