From 5ff89fc9fe7fbd2f4f7a54caff75628d929981a8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 25 May 2018 16:00:03 +0200 Subject: [PATCH 1/2] dont open the file on dav HEAD request Signed-off-by: Robin Appelman --- sabre/dav/lib/DAV/CorePlugin.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) 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, From 9d6f50423a7f526e266d2d572d9fa21c5a29504a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 23 May 2018 15:15:05 +0200 Subject: [PATCH 2/2] Add to patch list Signed-off-by: Robin Appelman --- patches.txt | 1 + 1 file changed, 1 insertion(+) 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