Skip to content

Commit

Permalink
Update Issue 19
Browse files Browse the repository at this point in the history
Now returning HTTP 200 for HEAD on non-files
  • Loading branch information
evert committed Feb 24, 2010
1 parent d56d5c6 commit 3714774
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
uri's.
* Changed: Sabre_HTTP_Response now returns false if headers are already
sent and header-methods are called.
* Fixed: Issue 19: HEAD requests on Collections

1.0.5-stable (2010-01-22)
* Fixed: Fatal error when a malformed url was used for unlocking, in
Expand Down
28 changes: 17 additions & 11 deletions lib/Sabre/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,28 @@ protected function httpHead() {

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

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

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

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

$this->httpResponse->setHeader('ETag',$etag);
}

}
if (!$contentType = $node->getContentType())
$contentType = 'application/octet-stream';

if (!$contentType = $node->getContentType())
$contentType = 'application/octet-stream';

$this->httpResponse->setHeader('Content-Type', $contentType);
$this->httpResponse->setHeader('Last-Modified', date(DateTime::RFC1123, $node->getLastModified()));
$this->httpResponse->setHeader('Content-Type', $contentType);
if ($lastMod = $node->getLastModified()) {
$this->httpResponse->setHeader('Last-Modified', date(DateTime::RFC1123, $node->getLastModified()));
}
}
$this->httpResponse->sendStatus(200);

}
Expand Down
6 changes: 1 addition & 5 deletions tests/Sabre/DAV/ServerSimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,7 @@ function testHEADOnCollection() {
$this->server->httpRequest = ($request);
$this->server->exec();

$this->assertEquals(array(
'Content-Type' => 'application/xml; charset=utf-8',
),$this->response->headers);

$this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status);
$this->assertEquals('HTTP/1.1 200 Ok',$this->response->status);

}

Expand Down

0 comments on commit 3714774

Please sign in to comment.