String depthString = req.getHeader("Depth");
int depth = Integer.MAX_VALUE;
OutputStream os = res.getOutputStream();
WriteStream out = Vfs.openWrite(os);
out.setEncoding("UTF-8");
if (_addCrLf)
out.setNewlineString("\r\n");
try {
if ("0".equals(depthString))
depth = 0;
else if ("1".equals(depthString))
depth = 1;
if (req.getMethod().equals("OPTIONS")) {
res.setHeader("DAV", "1");
res.setHeader("MS-Author-Via", "DAV");
if (_enableWrite)
res.setHeader("Allow", "OPTIONS, PROPFIND, GET, HEAD, PUT, MKCOL, DELETE, COPY, MOVE, PROPPATCH");
else if (_enable)
res.setHeader("Allow", "OPTIONS, PROPFIND, GET, HEAD");
}
else if (req.getMethod().equals("PROPFIND")) {
handlePropfind(req, res, out, depth);
}
else if (req.getMethod().equals("GET") ||
req.getMethod().equals("HEAD")) {
handleGet(req, res, out);
}
else if (req.getMethod().equals("PUT") && _enableWrite) {
handlePut(req, res, out);
}
else if (req.getMethod().equals("MKCOL") && _enableWrite) {
handleMkcol(req, res, out);
}
else if (req.getMethod().equals("DELETE") && _enableWrite) {
handleDelete(req, res, out);
}
else if (req.getMethod().equals("COPY") && _enableWrite) {
handleCopy(req, res, out, depth);
}
else if (req.getMethod().equals("MOVE") && _enableWrite) {
handleMove(req, res, out);
}
else if (req.getMethod().equals("PROPPATCH") && _enableWrite) {
handleProppatch(req, res, out, depth);
}
else if (! _enableWrite &&
"PUT".equals(req.getMethod()) ||
"MKCOL".equals(req.getMethod()) ||
"DELETE".equals(req.getMethod()) ||
"COPY".equals(req.getMethod()) ||
"MOVE".equals(req.getMethod()) ||
"PROPPATCH".equals(req.getMethod())) {
res.sendError(res.SC_FORBIDDEN);
}
else {
res.sendError(res.SC_NOT_IMPLEMENTED, "Method not implemented");
}
} finally {
out.close();
}
}