Skip to content
Snippets Groups Projects
Commit 4a18855a authored by srosse's avatar srosse
Browse files

OO-1072: don't let HEAD request be a WebDAV monopoly

parent 19b37335
No related branches found
No related tags found
No related merge requests found
......@@ -226,7 +226,14 @@ public class OpenOLATServlet extends HttpServlet {
@Override
protected void doHead(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
webDAVDispatcher.execute(req, resp);
String subContext = DispatcherModule.getFirstPath(req);
if("/".equals(subContext)) {
webDAVDispatcher.execute(req, resp);
} else if("/webdav".equals(subContext) || "/webdav/".equals(subContext)) {
webDAVDispatcher.execute(req, resp);
} else {
executeUserRequest(req, resp);
}
}
/**
......
......@@ -120,6 +120,33 @@ public class WebDAVCommandsTest extends WebDAVTestCase {
IOUtils.closeQuietly(conn);
}
@Test
public void testHead()
throws IOException, URISyntaxException {
//create a user
Identity user = JunitTestHelper.createAndPersistIdentityAsUser("webdav-2-" + UUID.randomUUID().toString());
WebDAVConnection conn = new WebDAVConnection();
conn.setCredentials(user.getName(), "A6B7C8");
//create a file
String publicPath = FolderConfig.getUserHomes() + "/" + user.getName() + "/public";
VFSContainer vfsPublic = new OlatRootFolderImpl(publicPath, null);
createFile(vfsPublic, "test_head.txt");
//head file
URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test_head.txt").build();
HttpResponse response = conn.head(publicUri);
Header lengthHeader = response.getFirstHeader("Content-Length");
Assert.assertNotNull(lengthHeader);
Assert.assertEquals("0", lengthHeader.getValue());
Header typeHeader = response.getFirstHeader("Content-Type");
Assert.assertNotNull(typeHeader);
Assert.assertEquals("text/plain", typeHeader.getValue());
EntityUtils.consume(response.getEntity());
IOUtils.closeQuietly(conn);
}
@Test
public void testPropFind()
throws IOException, URISyntaxException {
......
......@@ -38,6 +38,7 @@ import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpOptions;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
......@@ -93,6 +94,13 @@ public class WebDAVConnection implements Closeable {
return response;
}
public HttpResponse head(URI uri) throws IOException, URISyntaxException {
HttpHead propfind = new HttpHead(uri);
HttpResponse response = execute(propfind);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
return response;
}
public String propfind(URI uri, int depth) throws IOException, URISyntaxException {
HttpPropFind propfind = new HttpPropFind(uri);
propfind.addHeader("Depth", Integer.toString(depth));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment