1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -58,6 +58,7 @@ public class DefaultCorsProcessor implements CorsProcessor {
58
58
59
59
60
60
@ Override
61
+ @ SuppressWarnings ("resource" )
61
62
public boolean processRequest (CorsConfiguration config , HttpServletRequest request , HttpServletResponse response )
62
63
throws IOException {
63
64
@@ -66,14 +67,14 @@ public boolean processRequest(CorsConfiguration config, HttpServletRequest reque
66
67
}
67
68
68
69
ServletServerHttpResponse serverResponse = new ServletServerHttpResponse (response );
69
- ServletServerHttpRequest serverRequest = new ServletServerHttpRequest (request );
70
-
71
- if (WebUtils .isSameOrigin (serverRequest )) {
72
- logger .debug ("Skip CORS processing, request is a same-origin one" );
70
+ if (responseHasCors (serverResponse )) {
71
+ logger .debug ("Skip CORS processing: response already contains \" Access-Control-Allow-Origin\" header" );
73
72
return true ;
74
73
}
75
- if (responseHasCors (serverResponse )) {
76
- logger .debug ("Skip CORS processing, response already contains \" Access-Control-Allow-Origin\" header" );
74
+
75
+ ServletServerHttpRequest serverRequest = new ServletServerHttpRequest (request );
76
+ if (WebUtils .isSameOrigin (serverRequest )) {
77
+ logger .debug ("Skip CORS processing: request is from same origin" );
77
78
return true ;
78
79
}
79
80
@@ -92,14 +93,13 @@ public boolean processRequest(CorsConfiguration config, HttpServletRequest reque
92
93
}
93
94
94
95
private boolean responseHasCors (ServerHttpResponse response ) {
95
- boolean hasAllowOrigin = false ;
96
96
try {
97
- hasAllowOrigin = (response .getHeaders ().getAccessControlAllowOrigin () != null );
97
+ return (response .getHeaders ().getAccessControlAllowOrigin () != null );
98
98
}
99
99
catch (NullPointerException npe ) {
100
100
// SPR-11919 and https://issues.jboss.org/browse/WFLY-3474
101
+ return false ;
101
102
}
102
- return hasAllowOrigin ;
103
103
}
104
104
105
105
/**
@@ -163,7 +163,7 @@ protected boolean handleInternal(ServerHttpRequest request, ServerHttpResponse r
163
163
/**
164
164
* Check the origin and determine the origin for the response. The default
165
165
* implementation simply delegates to
166
- * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}
166
+ * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}.
167
167
*/
168
168
protected String checkOrigin (CorsConfiguration config , String requestOrigin ) {
169
169
return config .checkOrigin (requestOrigin );
@@ -172,7 +172,7 @@ protected String checkOrigin(CorsConfiguration config, String requestOrigin) {
172
172
/**
173
173
* Check the HTTP method and determine the methods for the response of a
174
174
* pre-flight request. The default implementation simply delegates to
175
- * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}
175
+ * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}.
176
176
*/
177
177
protected List <HttpMethod > checkMethods (CorsConfiguration config , HttpMethod requestMethod ) {
178
178
return config .checkHttpMethod (requestMethod );
@@ -185,7 +185,7 @@ private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight
185
185
/**
186
186
* Check the headers and determine the headers for the response of a
187
187
* pre-flight request. The default implementation simply delegates to
188
- * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}
188
+ * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}.
189
189
*/
190
190
protected List <String > checkHeaders (CorsConfiguration config , List <String > requestHeaders ) {
191
191
return config .checkHeaders (requestHeaders );
0 commit comments