[Pkg-owncloud-commits] [php-sabredav] 110/148: Removed the need of temp files from the handling of Range requests

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 3db14a93d79d4638e580d36d73322fdad483b3c5
Author: dratini0 <dratini0 at gmail.com>
Date:   Thu Apr 2 00:20:19 2015 +0200

    Removed the need of temp files from the handling of Range requests
    
    Requires the matching commit for sabre-http, which makes sendResponse respect Content-Length. Also adjusted the unit tests to reflect these changes.
---
 lib/DAV/CorePlugin.php              | 23 ++++++++++-------------
 tests/Sabre/DAV/ServerRangeTest.php | 10 +++++-----
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/lib/DAV/CorePlugin.php b/lib/DAV/CorePlugin.php
index 62a8311..e68576a 100644
--- a/lib/DAV/CorePlugin.php
+++ b/lib/DAV/CorePlugin.php
@@ -170,24 +170,21 @@ class CorePlugin extends ServerPlugin {
 
             }
 
-            // New read/write stream
-            $newStream = fopen('php://temp','r+');
-
-            // fseek will return 0 only if $streem is seekable (and -1 otherwise)
-            // for a seekable $body stream we set the pointer write before copying it
-            // for a non-seekable $body stream we set the pointer on the copy
-            if ((fseek($body, $start, SEEK_SET)) === 0) {
-                stream_copy_to_stream($body, $newStream, $end - $start + 1, $start);
-                rewind($newStream);
-            } else {
-                stream_copy_to_stream($body, $newStream, $end + 1);
-                fseek($newStream,$start, SEEK_SET);
+            // fseek will return 0 only if $stream is seekable (and -1 otherwise)
+            // for a seekable $body stream we simply set the pointer
+            // for a non-seekable $body stream we read and discard just the
+            //  right amount of data
+            if ((fseek($body, $start, SEEK_SET)) !== 0) {
+                $consume_block = 4096;
+                for($consumed = 0; $start - $consumed > 0; ){
+                    $consumed += strlen(fread($body, min($start - $consumed, $consume_block)));
+                }
             }
 
             $response->setHeader('Content-Length', $end - $start + 1);
             $response->setHeader('Content-Range','bytes ' . $start . '-' . $end . '/' . $nodeSize);
             $response->setStatus(206);
-            $response->setBody($newStream);
+            $response->setBody($body);
 
         } else {
 
diff --git a/tests/Sabre/DAV/ServerRangeTest.php b/tests/Sabre/DAV/ServerRangeTest.php
index 07a0d8a..5dfd5ae 100644
--- a/tests/Sabre/DAV/ServerRangeTest.php
+++ b/tests/Sabre/DAV/ServerRangeTest.php
@@ -38,7 +38,7 @@ class ServerRangeTest extends AbstractServer{
          );
 
         $this->assertEquals(206, $this->response->status);
-        $this->assertEquals('st c', stream_get_contents($this->response->body));
+        $this->assertEquals('st c', stream_get_contents($this->response->body, 4));
 
     }
 
@@ -70,7 +70,7 @@ class ServerRangeTest extends AbstractServer{
          );
 
         $this->assertEquals(206, $this->response->status);
-        $this->assertEquals('st contents', stream_get_contents($this->response->body));
+        $this->assertEquals('st contents', stream_get_contents($this->response->body, 11));
 
     }
 
@@ -102,7 +102,7 @@ class ServerRangeTest extends AbstractServer{
          );
 
         $this->assertEquals(206, $this->response->status);
-        $this->assertEquals('contents', stream_get_contents($this->response->body));
+        $this->assertEquals('contents', stream_get_contents($this->response->body, 8));
 
     }
 
@@ -175,7 +175,7 @@ class ServerRangeTest extends AbstractServer{
          );
 
         $this->assertEquals(206, $this->response->status);
-        $this->assertEquals('st c', stream_get_contents($this->response->body));
+        $this->assertEquals('st c', stream_get_contents($this->response->body, 4));
 
     }
 
@@ -244,7 +244,7 @@ class ServerRangeTest extends AbstractServer{
          );
 
         $this->assertEquals(206, $this->response->status);
-        $this->assertEquals('st c', stream_get_contents($this->response->body));
+        $this->assertEquals('st c', stream_get_contents($this->response->body, 4));
 
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list