diff --git a/patches.txt b/patches.txt index 7ac20294d..3c3ce431d 100644 --- a/patches.txt +++ b/patches.txt @@ -3,6 +3,7 @@ Patches: - patchwork/utf8: Remove trigger_error() that spammed the error log - Doctrine: fix error handling for not null columns on some mysql servers https://github.com/doctrine/dbal/pull/2422 - SabreDAV: Make sure that files that are children of directories, are reported as files https://github.com/fruux/sabre-dav/issues/982 +- SabreDAV: Don't open the file on HEAD requests https://github.com/sabre-io/dav/pull/1058 - SabreXML: Fix invalid PHP docs https://github.com/fruux/sabre-xml/pull/128 - SabreXML: Prevent infinite loops for empty props element https://github.com/fruux/sabre-xml/pull/132 - ZipStreamer: Fix zip generation for 7zip https://github.com/McNetic/PHPZipStreamer/pull/39 diff --git a/sabre/dav/lib/DAV/CorePlugin.php b/sabre/dav/lib/DAV/CorePlugin.php index 676cdd04a..95da21f4a 100644 --- a/sabre/dav/lib/DAV/CorePlugin.php +++ b/sabre/dav/lib/DAV/CorePlugin.php @@ -82,14 +82,18 @@ function httpGet(RequestInterface $request, ResponseInterface $response) { if (!$node instanceof IFile) return; - $body = $node->get(); - - // Converting string into stream, if needed. - if (is_string($body)) { - $stream = fopen('php://temp', 'r+'); - fwrite($stream, $body); - rewind($stream); - $body = $stream; + if ($request->getHeader('X-Sabre-Original-Method') === 'HEAD') { + $body = ''; + } else { + $body = $node->get(); + + // Converting string into stream, if needed. + if (is_string($body)) { + $stream = fopen('php://temp', 'r+'); + fwrite($stream, $body); + rewind($stream); + $body = $stream; + } } /* @@ -245,13 +249,13 @@ function httpOptions(RequestInterface $request, ResponseInterface $response) { function httpHead(RequestInterface $request, ResponseInterface $response) { // This is implemented by changing the HEAD request to a GET request, - // and dropping the response body. + // and telling the request handler that is doesn't need to create the body. $subRequest = clone $request; $subRequest->setMethod('GET'); + $subRequest->setHeader('X-Sabre-Original-Method', 'HEAD'); try { $this->server->invokeMethod($subRequest, $response, false); - $response->setBody(''); } catch (Exception\NotImplemented $e) { // Some clients may do HEAD requests on collections, however, GET // requests and HEAD requests _may_ not be defined on a collection,