Skip to content

Commit 9c29ed7

Browse files
committed
Suppress OPTIONS handling for an ERROR dispatch
Issue: SPR-14410
1 parent 1694994 commit 9c29ed7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.LinkedHashSet;
2323
import java.util.List;
2424
import java.util.Set;
25+
import javax.servlet.DispatcherType;
2526
import javax.servlet.http.HttpServletRequest;
2627

2728
import org.springframework.http.HttpHeaders;
@@ -109,7 +110,9 @@ public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest re
109110
}
110111

111112
if (getMethods().isEmpty()) {
112-
if (RequestMethod.OPTIONS.name().equals(request.getMethod())) {
113+
if (RequestMethod.OPTIONS.name().equals(request.getMethod()) &&
114+
!DispatcherType.ERROR.equals(request.getDispatcherType())) {
115+
113116
return null; // No implicit match for OPTIONS (we handle it)
114117
}
115118
return this;

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestConditionTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Collections;
2020

21+
import javax.servlet.DispatcherType;
2122
import javax.servlet.http.HttpServletRequest;
2223

2324
import org.junit.Test;
@@ -29,6 +30,7 @@
2930
import static org.junit.Assert.assertEquals;
3031
import static org.junit.Assert.assertNotNull;
3132
import static org.junit.Assert.assertNull;
33+
import static org.junit.Assert.assertSame;
3234
import static org.junit.Assert.assertTrue;
3335
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
3436
import static org.springframework.web.bind.annotation.RequestMethod.GET;
@@ -87,6 +89,18 @@ public void getMatchingConditionWithCorsPreFlight() throws Exception {
8789
assertNull(new RequestMethodsRequestCondition(DELETE).getMatchingCondition(request));
8890
}
8991

92+
@Test // SPR-14410
93+
public void getMatchingConditionWithHttpOptionsInErrorDispatch() throws Exception {
94+
MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/path");
95+
request.setDispatcherType(DispatcherType.ERROR);
96+
97+
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
98+
RequestMethodsRequestCondition result = condition.getMatchingCondition(request);
99+
100+
assertNotNull(result);
101+
assertSame(condition, result);
102+
}
103+
90104
@Test
91105
public void compareTo() {
92106
RequestMethodsRequestCondition c1 = new RequestMethodsRequestCondition(GET, HEAD);

0 commit comments

Comments
 (0)