Suppress OPTIONS handling for an ERROR dispatch

Issue: SPR-14410
This commit is contained in:
Rossen Stoyanchev 2016-06-30 12:34:54 -04:00
parent 16949941f8
commit 9c29ed75f8
2 changed files with 18 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -109,7 +110,9 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
} }
if (getMethods().isEmpty()) { 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 null; // No implicit match for OPTIONS (we handle it)
} }
return this; return this;

View File

@ -18,6 +18,7 @@ package org.springframework.web.servlet.mvc.condition;
import java.util.Collections; import java.util.Collections;
import javax.servlet.DispatcherType;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.junit.Test; 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.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.springframework.web.bind.annotation.RequestMethod.DELETE; import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
import static org.springframework.web.bind.annotation.RequestMethod.GET; import static org.springframework.web.bind.annotation.RequestMethod.GET;
@ -87,6 +89,18 @@ public class RequestMethodsRequestConditionTests {
assertNull(new RequestMethodsRequestCondition(DELETE).getMatchingCondition(request)); 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 @Test
public void compareTo() { public void compareTo() {
RequestMethodsRequestCondition c1 = new RequestMethodsRequestCondition(GET, HEAD); RequestMethodsRequestCondition c1 = new RequestMethodsRequestCondition(GET, HEAD);