类 DefaultCorsProcessor
- java.lang.Object
- org.springframework.web.cors.DefaultCorsProcessor
- 所有已实现的接口:
CorsProcessor
public class DefaultCorsProcessor extends Object implements CorsProcessor
The default implementation ofCorsProcessor
, as defined by the CORS W3C recommendation.Note that when input
CorsConfiguration
isnull
, this implementation does not reject simple or actual requests outright but simply avoid adding CORS headers to the response. CORS processing is also skipped if the response already contains CORS headers, or if the request is detected as a same-origin one.- 从以下版本开始:
- 4.2
- 作者:
- Sebastien Deleuze, Rossen Stoyanchev
构造器概要
构造器 构造器 说明 DefaultCorsProcessor()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected List<String>
checkHeaders(CorsConfiguration config, List<String> requestHeaders)
Check the headers and determine the headers for the response of a pre-flight request.protected List<HttpMethod>
checkMethods(CorsConfiguration config, HttpMethod requestMethod)
Check the HTTP method and determine the methods for the response of a pre-flight request.protected String
checkOrigin(CorsConfiguration config, String requestOrigin)
Check the origin and determine the origin for the response.protected boolean
handleInternal(ServerHttpRequest request, ServerHttpResponse response, CorsConfiguration config, boolean preFlightRequest)
Handle the given request.boolean
processRequest(CorsConfiguration config, HttpServletRequest request, HttpServletResponse response)
Process a request given aCorsConfiguration
.protected void
rejectRequest(ServerHttpResponse response)
Invoked when one of the CORS checks failed.
构造器详细资料
DefaultCorsProcessor
public DefaultCorsProcessor()
方法详细资料
processRequest
public boolean processRequest(CorsConfiguration config, HttpServletRequest request, HttpServletResponse response) throws IOException
从接口复制的说明:CorsProcessor
Process a request given aCorsConfiguration
.- 指定者:
processRequest
在接口中CorsProcessor
- 参数:
config
- the applicable CORS configuration (possiblynull
)request
- the current requestresponse
- the current response- 返回:
false
if the request is rejected,true
otherwise- 抛出:
IOException
rejectRequest
protected void rejectRequest(ServerHttpResponse response) throws IOException
Invoked when one of the CORS checks failed. The default implementation sets the response status to 403 and writes "Invalid CORS request" to the response.- 抛出:
IOException
handleInternal
protected boolean handleInternal(ServerHttpRequest request, ServerHttpResponse response, CorsConfiguration config, boolean preFlightRequest) throws IOException
Handle the given request.- 抛出:
IOException
checkOrigin
protected String checkOrigin(CorsConfiguration config, String requestOrigin)
Check the origin and determine the origin for the response. The default implementation simply delegates toCorsConfiguration.checkOrigin(String)
.
checkMethods
protected List<HttpMethod> checkMethods(CorsConfiguration config, HttpMethod requestMethod)
Check the HTTP method and determine the methods for the response of a pre-flight request. The default implementation simply delegates toCorsConfiguration.checkHttpMethod(HttpMethod)
.
checkHeaders
protected List<String> checkHeaders(CorsConfiguration config, List<String> requestHeaders)
Check the headers and determine the headers for the response of a pre-flight request. The default implementation simply delegates toCorsConfiguration.checkOrigin(String)
.