From: <jbo...@li...> - 2006-03-05 15:52:45
|
Author: mnasato Date: 2006-03-05 10:52:32 -0500 (Sun, 05 Mar 2006) New Revision: 2752 Modified: trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java Log: fail in MKCOL if missing parent path [#14] or non-empty request body [#15] Modified: trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java =================================================================== --- trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java 2006-03-05 14:40:15 UTC (rev 2751) +++ trunk/labs/davcache/src/net/sf/davcache/WebdavServlet.java 2006-03-05 15:52:32 UTC (rev 2752) @@ -321,17 +321,28 @@ } } - protected void doMkCol(HttpServletRequest request, HttpServletResponse response) throws IOException, - ServletException + protected void doMkCol(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String path = getRelativePath(request); if (store.exists(path)) { logger.debug("cannot create directory; file already exists: '" + path + "'"); - response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, - "Method Not Allowed: collection already exists: " + path); + response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method Not Allowed: collection already exists: " + path); return; } + String parentPath = getParentPath(path); + if (parentPath != null && !store.exists(parentPath)) + { + logger.debug("cannot create directory; parent does not exist: '" + path + "'"); + response.sendError(HttpServletResponse.SC_CONFLICT, "Conflict: parent path does not exist"); + return; + } + if (request.getContentLength() > 0) + { + // we only support MKCOL with empty request body; see RFC2518:8.3.1 + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type"); + return; + } try { logger.debug("creating directory '" + path + "'"); @@ -344,9 +355,16 @@ } } - protected void doPropFind(HttpServletRequest request, HttpServletResponse response) throws IOException, - ServletException + private String getParentPath(String path) { + int slash = path.lastIndexOf('/'); + if (slash == -1) + return null; + return path.substring(0, slash); + } + + protected void doPropFind(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { int depth = getDepth(request); if (depth == DEPTH_INFINITY) { |