You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2003/11/14 11:16:22 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets WebdavServlet.java
remm 2003/11/14 02:16:22
Modified: catalina/src/share/org/apache/catalina/servlets
WebdavServlet.java
Log:
- Allow header handling.
- Bug 24006, submitted by Mark Thomas.
Revision Changes Path
1.6 +64 -31 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java
Index: WebdavServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebdavServlet.java 6 Oct 2003 08:05:46 -0000 1.5
+++ WebdavServlet.java 14 Nov 2003 10:16:22 -0000 1.6
@@ -338,11 +338,8 @@
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
- String path = getRelativePath(req);
-
resp.addHeader("DAV", "1,2");
- String methodsAllowed = null;
-
+
// Retrieve the resources
DirContext resources = getResources();
@@ -351,28 +348,10 @@
return;
}
- boolean exists = true;
- Object object = null;
- try {
- object = resources.lookup(path);
- } catch (NamingException e) {
- exists = false;
- }
-
- if (!exists) {
- methodsAllowed = "OPTIONS, MKCOL, PUT, LOCK";
- resp.addHeader("Allow", methodsAllowed);
- return;
- }
-
- methodsAllowed = "OPTIONS, GET, HEAD, POST, DELETE, TRACE, "
- + "PROPFIND, PROPPATCH, COPY, MOVE, LOCK, UNLOCK";
- if (!(object instanceof DirContext)) {
- methodsAllowed += ", PUT";
- }
-
- resp.addHeader("Allow", methodsAllowed);
+ StringBuffer methodsAllowed = determineMethodsAllowed(resources,
+ req);
+ resp.addHeader("Allow", methodsAllowed.toString());
resp.addHeader("MS-Author-Via", "DAV");
}
@@ -385,6 +364,19 @@
throws ServletException, IOException {
if (!listings) {
+ // Retrieve the resources
+ DirContext resources = getResources();
+
+ if (resources == null) {
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ // Get allowed methods
+ StringBuffer methodsAllowed = determineMethodsAllowed(resources,
+ req);
+
+ resp.addHeader("Allow", methodsAllowed.toString());
resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
return;
}
@@ -649,7 +641,7 @@
return;
}
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
}
@@ -697,6 +689,12 @@
// Can't create a collection if a resource already exists at the given
// path
if (exists) {
+ // Get allowed methods
+ StringBuffer methodsAllowed = determineMethodsAllowed(resources,
+ req);
+
+ resp.addHeader("Allow", methodsAllowed.toString());
+
resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
return;
}
@@ -2566,6 +2564,42 @@
return creationDateValue.toString();
}
+ /**
+ * Determines the methods normally allowed for the resource.
+ *
+ */
+ private StringBuffer determineMethodsAllowed(DirContext resources,
+ HttpServletRequest req) {
+
+ StringBuffer methodsAllowed = new StringBuffer();
+ boolean exists = true;
+ Object object = null;
+ try {
+ String path = getRelativePath(req);
+
+ object = resources.lookup(path);
+ } catch (NamingException e) {
+ exists = false;
+ }
+
+ if (!exists) {
+ methodsAllowed.append("OPTIONS, MKCOL, PUT, LOCK");
+ return methodsAllowed;
+ }
+
+ methodsAllowed.append("OPTIONS, GET, HEAD, POST, DELETE, TRACE, ");
+ methodsAllowed.append("PROPPATCH, COPY, MOVE, LOCK, UNLOCK");
+
+ if (listings) {
+ methodsAllowed.append("PROPFIND, ");
+ }
+
+ if (!(object instanceof DirContext)) {
+ methodsAllowed.append(", PUT");
+ }
+
+ return methodsAllowed;
+ }
// -------------------------------------------------- LockInfo Inner Class
@@ -3041,7 +3075,6 @@
private static void addStatusCodeMap(int nKey, String strVal) {
mapStatusCodes.put(new Integer(nKey), strVal);
}
-
};
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org