diff options
author | Robin Appelman <robin@icewind.nl> | 2016-10-27 14:46:28 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-11-16 15:30:36 +0100 |
commit | 4235b18a889cd9d1b306ea410ed8e8ec307730c1 (patch) | |
tree | f54609adf9eebfbee27d66e8e791a8a67a58619c /lib | |
parent | 0ee958595e42bc29543e294958b2090b80f85d2d (diff) | |
download | nextcloud-server-4235b18a889cd9d1b306ea410ed8e8ec307730c1.tar.gz nextcloud-server-4235b18a889cd9d1b306ea410ed8e8ec307730c1.zip |
allow passing a stream to StreamResponse
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/AppFramework/Http/Output.php | 9 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/IOutput.php | 2 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/StreamResponse.php | 4 |
3 files changed, 10 insertions, 5 deletions
diff --git a/lib/private/AppFramework/Http/Output.php b/lib/private/AppFramework/Http/Output.php index 85f0e6f8feb..1d77350b1a2 100644 --- a/lib/private/AppFramework/Http/Output.php +++ b/lib/private/AppFramework/Http/Output.php @@ -48,12 +48,17 @@ class Output implements IOutput { } /** - * @param string $path + * @param string|resource $path or file handle * * @return bool false if an error occurred */ public function setReadfile($path) { - return @readfile($path); + if (is_resource($path)) { + $output = fopen('php://output', 'w'); + return stream_copy_to_stream($path, $output) > 0; + } else { + return @readfile($path); + } } /** diff --git a/lib/public/AppFramework/Http/IOutput.php b/lib/public/AppFramework/Http/IOutput.php index 1544c7d6375..642bcf4170f 100644 --- a/lib/public/AppFramework/Http/IOutput.php +++ b/lib/public/AppFramework/Http/IOutput.php @@ -39,7 +39,7 @@ interface IOutput { public function setOutput($out); /** - * @param string $path + * @param string|resource $path or file handle * * @return bool false if an error occurred * @since 8.1.0 diff --git a/lib/public/AppFramework/Http/StreamResponse.php b/lib/public/AppFramework/Http/StreamResponse.php index b5852fb5620..e124bb4ccbf 100644 --- a/lib/public/AppFramework/Http/StreamResponse.php +++ b/lib/public/AppFramework/Http/StreamResponse.php @@ -37,7 +37,7 @@ class StreamResponse extends Response implements ICallbackResponse { private $filePath; /** - * @param string $filePath the path to the file which should be streamed + * @param string|resource $filePath the path to the file or a file handle which should be streamed * @since 8.1.0 */ public function __construct ($filePath) { @@ -54,7 +54,7 @@ class StreamResponse extends Response implements ICallbackResponse { public function callback (IOutput $output) { // handle caching if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { - if (!file_exists($this->filePath)) { + if (!(file_exists($this->filePath) || is_resource($this->filePath))) { $output->setHttpResponseCode(Http::STATUS_NOT_FOUND); } elseif ($output->setReadfile($this->filePath) === false) { $output->setHttpResponseCode(Http::STATUS_BAD_REQUEST); |