RequestMethodsRequestCondition uses common HttpMethod resolution

Issue: SPR-13776
This commit is contained in:
Juergen Hoeller 2016-03-24 13:54:00 +01:00
parent 86d5c5c0f7
commit 3eff478c45
1 changed files with 6 additions and 15 deletions

View File

@ -25,6 +25,7 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.cors.CorsUtils;
@ -103,7 +104,6 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
*/
@Override
public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest request) {
if (CorsUtils.isPreFlightRequest(request)) {
return matchPreFlight(request);
}
@ -131,30 +131,21 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
return matchRequestMethod(expectedMethod);
}
private RequestMethodsRequestCondition matchRequestMethod(String httpMethod) {
RequestMethod requestMethod = getRequestMethod(httpMethod);
if (requestMethod != null) {
private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) {
HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue);
if (httpMethod != null) {
for (RequestMethod method : getMethods()) {
if (method.equals(requestMethod)) {
if (httpMethod.matches(method.name())) {
return new RequestMethodsRequestCondition(method);
}
}
if (RequestMethod.HEAD.equals(requestMethod) && getMethods().contains(RequestMethod.GET)) {
if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
return HEAD_CONDITION;
}
}
return null;
}
private RequestMethod getRequestMethod(String httpMethod) {
try {
return RequestMethod.valueOf(httpMethod);
}
catch (IllegalArgumentException ex) {
return null;
}
}
/**
* Returns:
* <ul>