Browse files

default behavior of http options should be keeped in DefaultMethodNot…

…AllowedHandler, so I'm reverting the previous update
  • Loading branch information...
1 parent 8b0abb3 commit 6e78548b784f04a7268472b14c66146e8d9eef95 @douglasrodrigo douglasrodrigo committed Oct 30, 2012
View
4 ...tor-core/src/main/java/br/com/caelum/vraptor/resource/DefaultMethodNotAllowedHandler.java
@@ -38,7 +38,9 @@ public void deny(RequestInfo request, Set<HttpMethod> allowedMethods) {
request.getResponse().addHeader(
"Allow", allowedMethods.toString().replaceAll("\\[|\\]", ""));
try {
- request.getResponse().sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ if (!"OPTIONS".equalsIgnoreCase(request.getRequest().getMethod())) {
+ request.getResponse().sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ }
} catch (IOException e) {
throw new InterceptionException(e);
}
View
7 ...core/src/test/java/br/com/caelum/vraptor/resource/DefaultMethodNotAllowedHandlerTest.java
@@ -3,6 +3,7 @@
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -50,12 +51,12 @@ public void shouldSendErrorMethodNotAllowed() throws Exception {
}
@Test
- public void shouldSendMethodNotAllowedIfTheRequestMethodIsOptions() throws Exception {
+ public void shouldNotSendMethodNotAllowedIfTheRequestMethodIsOptions() throws Exception {
when(mockRequest.getMethod()).thenReturn("OPTIONS");
- this.handler.deny(request, EnumSet.of(HttpMethod.OPTIONS));
+ this.handler.deny(request, EnumSet.of(HttpMethod.GET, HttpMethod.POST));
- verify(response).sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ verify(response, never()).sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}
@Test(expected=InterceptionException.class)

0 comments on commit 6e78548

Please sign in to comment.