Skip to content

Commit 3714774

Browse files
committed
Update Issue 19
Now returning HTTP 200 for HEAD on non-files
1 parent d56d5c6 commit 3714774

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
uri's.
2121
* Changed: Sabre_HTTP_Response now returns false if headers are already
2222
sent and header-methods are called.
23+
* Fixed: Issue 19: HEAD requests on Collections
2324

2425
1.0.5-stable (2010-01-22)
2526
* Fixed: Fatal error when a malformed url was used for unlocking, in

lib/Sabre/DAV/Server.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,28 @@ protected function httpHead() {
371371

372372
$node = $this->tree->getNodeForPath($this->getRequestUri());
373373

374-
if (!($node instanceof Sabre_DAV_IFile)) throw new Sabre_DAV_Exception_NotImplemented('HEAD is only implemented on File objects');
374+
/* This information is only collection for File objects.
375+
* Ideally we want to throw 405 Method Not Allowed for every
376+
* non-file, but MS Office does not like this
377+
*/
378+
if ($node instanceof Sabre_DAV_IFile) {
379+
if ($size = $node->getSize())
380+
$this->httpResponse->setHeader('Content-Length',$size);
375381

376-
if ($size = $node->getSize())
377-
$this->httpResponse->setHeader('Content-Length',$size);
382+
if ($etag = $node->getETag()) {
378383

379-
if ($etag = $node->getETag()) {
384+
$this->httpResponse->setHeader('ETag',$etag);
380385

381-
$this->httpResponse->setHeader('ETag',$etag);
386+
}
382387

383-
}
388+
if (!$contentType = $node->getContentType())
389+
$contentType = 'application/octet-stream';
384390

385-
if (!$contentType = $node->getContentType())
386-
$contentType = 'application/octet-stream';
387-
388-
$this->httpResponse->setHeader('Content-Type', $contentType);
389-
$this->httpResponse->setHeader('Last-Modified', date(DateTime::RFC1123, $node->getLastModified()));
391+
$this->httpResponse->setHeader('Content-Type', $contentType);
392+
if ($lastMod = $node->getLastModified()) {
393+
$this->httpResponse->setHeader('Last-Modified', date(DateTime::RFC1123, $node->getLastModified()));
394+
}
395+
}
390396
$this->httpResponse->sendStatus(200);
391397

392398
}

tests/Sabre/DAV/ServerSimpleTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,7 @@ function testHEADOnCollection() {
328328
$this->server->httpRequest = ($request);
329329
$this->server->exec();
330330

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);
331+
$this->assertEquals('HTTP/1.1 200 Ok',$this->response->status);
336332

337333
}
338334

0 commit comments

Comments
 (0)