Skip to content

Commit 3eff478

Browse files
committed
RequestMethodsRequestCondition uses common HttpMethod resolution
Issue: SPR-13776
1 parent 86d5c5c commit 3eff478

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.servlet.http.HttpServletRequest;
2626

2727
import org.springframework.http.HttpHeaders;
28+
import org.springframework.http.HttpMethod;
2829
import org.springframework.web.bind.annotation.RequestMethod;
2930
import org.springframework.web.cors.CorsUtils;
3031

@@ -103,7 +104,6 @@ public RequestMethodsRequestCondition combine(RequestMethodsRequestCondition oth
103104
*/
104105
@Override
105106
public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest request) {
106-
107107
if (CorsUtils.isPreFlightRequest(request)) {
108108
return matchPreFlight(request);
109109
}
@@ -131,30 +131,21 @@ private RequestMethodsRequestCondition matchPreFlight(HttpServletRequest request
131131
return matchRequestMethod(expectedMethod);
132132
}
133133

134-
private RequestMethodsRequestCondition matchRequestMethod(String httpMethod) {
135-
RequestMethod requestMethod = getRequestMethod(httpMethod);
136-
if (requestMethod != null) {
134+
private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) {
135+
HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue);
136+
if (httpMethod != null) {
137137
for (RequestMethod method : getMethods()) {
138-
if (method.equals(requestMethod)) {
138+
if (httpMethod.matches(method.name())) {
139139
return new RequestMethodsRequestCondition(method);
140140
}
141141
}
142-
if (RequestMethod.HEAD.equals(requestMethod) && getMethods().contains(RequestMethod.GET)) {
142+
if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
143143
return HEAD_CONDITION;
144144
}
145145
}
146146
return null;
147147
}
148148

149-
private RequestMethod getRequestMethod(String httpMethod) {
150-
try {
151-
return RequestMethod.valueOf(httpMethod);
152-
}
153-
catch (IllegalArgumentException ex) {
154-
return null;
155-
}
156-
}
157-
158149
/**
159150
* Returns:
160151
* <ul>

0 commit comments

Comments
 (0)