Skip to content

Commit d56d5c6

Browse files
committed
Throwing 501 for HEAD on non-files
Update issue #19 Fixed issue on trunk
1 parent 4479091 commit d56d5c6

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/Sabre/DAV/Server.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@ protected function httpGet() {
370370
protected function httpHead() {
371371

372372
$node = $this->tree->getNodeForPath($this->getRequestUri());
373-
if ($node instanceof Sabre_DAV_IFile && $size = $node->getSize())
373+
374+
if (!($node instanceof Sabre_DAV_IFile)) throw new Sabre_DAV_Exception_NotImplemented('HEAD is only implemented on File objects');
375+
376+
if ($size = $node->getSize())
374377
$this->httpResponse->setHeader('Content-Length',$size);
375378

376379
if ($etag = $node->getETag()) {

tests/Sabre/DAV/ServerSimpleTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,44 @@ function testNonExistantMethod() {
298298

299299
}
300300

301+
function testGETOnCollection() {
302+
303+
$serverVars = array(
304+
'REQUEST_URI' => '/',
305+
'REQUEST_METHOD' => 'GET',
306+
);
307+
308+
$request = new Sabre_HTTP_Request($serverVars);
309+
$this->server->httpRequest = ($request);
310+
$this->server->exec();
311+
312+
$this->assertEquals(array(
313+
'Content-Type' => 'application/xml; charset=utf-8',
314+
),$this->response->headers);
315+
316+
$this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status);
317+
318+
}
319+
320+
function testHEADOnCollection() {
321+
322+
$serverVars = array(
323+
'REQUEST_URI' => '/',
324+
'REQUEST_METHOD' => 'HEAD',
325+
);
326+
327+
$request = new Sabre_HTTP_Request($serverVars);
328+
$this->server->httpRequest = ($request);
329+
$this->server->exec();
330+
331+
$this->assertEquals(array(
332+
'Content-Type' => 'application/xml; charset=utf-8',
333+
),$this->response->headers);
334+
335+
$this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status);
336+
337+
}
338+
301339
function testBaseUri() {
302340

303341
$serverVars = array(

0 commit comments

Comments
 (0)