404 rather than 405 or 200

Check that the path is valid and resolvable before checking that the
http method is supported. For invalid or unresolvable paths, always
respond with a 404.
This commit is contained in:
matthew-pearson
2016-02-14 09:19:04 +00:00
committed by Rossen Stoyanchev
parent a6d31d5212
commit 57b466fdfc
2 changed files with 94 additions and 12 deletions

View File

@@ -226,6 +226,14 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// First, check whether a matching resource exists
Resource resource = getResource(request);
if (resource == null) {
logger.trace("No matching resource found - returning 404");
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (HttpMethod.OPTIONS.matches(request.getMethod())) {
response.setHeader("Allow", getAllowHeader());
return;
@@ -234,14 +242,6 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
// Supported methods and required session
checkRequest(request);
// Check whether a matching resource exists
Resource resource = getResource(request);
if (resource == null) {
logger.trace("No matching resource found - returning 404");
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// Header phase
if (new ServletWebRequest(request, response).checkNotModified(resource.lastModified())) {
logger.trace("Resource not modified - returning 304");