Fix regression introduced in 4.3 snapshot
Commit ccd17d introduced a regression where a custom HTTP method would no longer match for an empty @RequestMapping condition. The previous behavior should now be restored. Effectively RequestMethodRequestCondition as before will now match to any HTTP method (even unknown/custom ones) if the methods condition is empty. The only exception is HTTP OPTIONS for which we provide default handling as a fallback (i.e. when not mapped explicitly). Issue: SPR-13130
This commit is contained in:
parent
1c2ac49f2a
commit
08eb623c41
|
@ -94,18 +94,18 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
|
|||
* Check if any of the HTTP request methods match the given request and
|
||||
* return an instance that contains the matching HTTP request method only.
|
||||
* @param request the current request
|
||||
* @return the same instance if the condition is empty, a new condition with
|
||||
* the matched request method, or {@code null} if no request methods match
|
||||
* @return the same instance if the condition is empty (unless the request
|
||||
* method is HTTP OPTIONS), a new condition with the matched request method,
|
||||
* or {@code null} if there is no match or the condition is empty and the
|
||||
* request method is OPTIONS.
|
||||
*/
|
||||
@Override
|
||||
public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest request) {
|
||||
RequestMethod requestMethod = getRequestMethod(request);
|
||||
if (requestMethod == null) {
|
||||
return null;
|
||||
}
|
||||
if (this.methods.isEmpty()) {
|
||||
return (RequestMethod.OPTIONS.equals(requestMethod) ? null : this);
|
||||
}
|
||||
if (requestMethod != null) {
|
||||
for (RequestMethod method : this.methods) {
|
||||
if (method.equals(requestMethod)) {
|
||||
return new RequestMethodsRequestCondition(method);
|
||||
|
@ -114,6 +114,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
|
|||
if (RequestMethod.HEAD.equals(requestMethod) && getMethods().contains(RequestMethod.GET)) {
|
||||
return HEAD_CONDITION;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,12 +82,13 @@ public class RequestMethodsRequestConditionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void noDeclaredMethodsMatchesAllMethodsExceptOptions() {
|
||||
public void emptyMatchesAnythingExceptHttpOptions() {
|
||||
RequestCondition condition = new RequestMethodsRequestCondition();
|
||||
|
||||
assertNotNull(condition.getMatchingCondition(new MockHttpServletRequest("GET", "")));
|
||||
assertNotNull(condition.getMatchingCondition(new MockHttpServletRequest("POST", "")));
|
||||
assertNotNull(condition.getMatchingCondition(new MockHttpServletRequest("HEAD", "")));
|
||||
assertNotNull(condition.getMatchingCondition(new MockHttpServletRequest("CUSTOM", "")));
|
||||
assertNull(condition.getMatchingCondition(new MockHttpServletRequest("OPTIONS", "")));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue