Suppress OPTIONS handling for an ERROR dispatch
Issue: SPR-14410
This commit is contained in:
parent
16949941f8
commit
9c29ed75f8
|
@ -22,6 +22,7 @@ import java.util.Collections;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -109,7 +110,9 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
|
|||
}
|
||||
|
||||
if (getMethods().isEmpty()) {
|
||||
if (RequestMethod.OPTIONS.name().equals(request.getMethod())) {
|
||||
if (RequestMethod.OPTIONS.name().equals(request.getMethod()) &&
|
||||
!DispatcherType.ERROR.equals(request.getDispatcherType())) {
|
||||
|
||||
return null; // No implicit match for OPTIONS (we handle it)
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.web.servlet.mvc.condition;
|
|||
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -29,6 +30,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
||||
|
@ -87,6 +89,18 @@ public class RequestMethodsRequestConditionTests {
|
|||
assertNull(new RequestMethodsRequestCondition(DELETE).getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@Test // SPR-14410
|
||||
public void getMatchingConditionWithHttpOptionsInErrorDispatch() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/path");
|
||||
request.setDispatcherType(DispatcherType.ERROR);
|
||||
|
||||
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
|
||||
RequestMethodsRequestCondition result = condition.getMatchingCondition(request);
|
||||
|
||||
assertNotNull(result);
|
||||
assertSame(condition, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTo() {
|
||||
RequestMethodsRequestCondition c1 = new RequestMethodsRequestCondition(GET, HEAD);
|
||||
|
|
Loading…
Reference in New Issue