Add PATCH to "Allow" header for OPTIONS requests
This commit is contained in:
parent
ce0ae84d95
commit
ef9d35c473
|
|
@ -785,7 +785,7 @@ public abstract class FrameworkServlet extends HttpServletBean {
|
||||||
|
|
||||||
String method = request.getMethod();
|
String method = request.getMethod();
|
||||||
if (method.equalsIgnoreCase(RequestMethod.PATCH.name())) {
|
if (method.equalsIgnoreCase(RequestMethod.PATCH.name())) {
|
||||||
doPatch(request, response);
|
processRequest(request, response);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
super.service(request, response);
|
super.service(request, response);
|
||||||
|
|
@ -828,16 +828,6 @@ public abstract class FrameworkServlet extends HttpServletBean {
|
||||||
processRequest(request, response);
|
processRequest(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delegate PATCH requests to {@link #processRequest}.
|
|
||||||
* @see #doService
|
|
||||||
*/
|
|
||||||
protected final void doPatch(HttpServletRequest request, HttpServletResponse response)
|
|
||||||
throws ServletException, IOException {
|
|
||||||
|
|
||||||
processRequest(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate DELETE requests to {@link #processRequest}.
|
* Delegate DELETE requests to {@link #processRequest}.
|
||||||
* @see #doService
|
* @see #doService
|
||||||
|
|
@ -867,6 +857,9 @@ public abstract class FrameworkServlet extends HttpServletBean {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.doOptions(request, response);
|
super.doOptions(request, response);
|
||||||
|
String allowedMethods = response.getHeader("Allow");
|
||||||
|
allowedMethods += ", " + RequestMethod.PATCH.name();
|
||||||
|
response.setHeader("Allow", allowedMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,12 @@
|
||||||
|
|
||||||
package org.springframework.web.servlet;
|
package org.springframework.web.servlet;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
|
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
@ -60,9 +66,6 @@ import org.springframework.web.servlet.theme.AbstractThemeResolver;
|
||||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
import org.springframework.web.util.WebUtils;
|
import org.springframework.web.util.WebUtils;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
@ -855,6 +858,14 @@ public class DispatcherServletTests extends TestCase {
|
||||||
assertThat(custom.getEnvironment(), instanceOf(CustomServletEnvironment.class));
|
assertThat(custom.getEnvironment(), instanceOf(CustomServletEnvironment.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAllowedOptionsIncludesPatchMethod() throws Exception {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "OPTIONS", "/foo");
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
DispatcherServlet servlet = new DispatcherServlet();
|
||||||
|
servlet.service(request, response);
|
||||||
|
assertThat(response.getHeader("Allow"), equalTo("GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ControllerFromParent implements Controller {
|
public static class ControllerFromParent implements Controller {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue