diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-01-22 20:26:46 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-02-27 15:42:33 +0100 |
commit | 95239ad21e113d7d25d5844b0ac5f15a606f2140 (patch) | |
tree | 384279227d5255640f3dec2c2e86b65e025b7df5 /lib/private/appframework/http | |
parent | 06141ed95a87e40dded4db6bedc4b643cdfdda0e (diff) | |
download | nextcloud-server-95239ad21e113d7d25d5844b0ac5f15a606f2140.tar.gz nextcloud-server-95239ad21e113d7d25d5844b0ac5f15a606f2140.zip |
AppFramework StreamResponse
First stab at the StreamResponse, see #12988
The idea is to use an interface ICallbackResponse (I'm not 100% happy with the name yet, suggestions?) that allow the response to output things in its own way, for instance stream the file using readfile
Unittests are atm lacking, plan is to
check if a mock of ICallbackResponse will be used by calling its callback (also unhappy with this name) method
Usage is:
$response = new StreamResponse('path/to/file');
rename io to output, add additional methods and handle error and not modified cases when using StreamResponse
fix indention and uppercasing, also handle forbidden cases
fix indention
fix indention
no forbidden, figuring out if a file is really readable is too complicated to get to work across OSes and streams
remove useless import
remove useless import
fix intendation
Diffstat (limited to 'lib/private/appframework/http')
-rw-r--r-- | lib/private/appframework/http/dispatcher.php | 10 | ||||
-rw-r--r-- | lib/private/appframework/http/output.php | 70 |
2 files changed, 74 insertions, 6 deletions
diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php index 24540ef3c94..910e9c32ed4 100644 --- a/lib/private/appframework/http/dispatcher.php +++ b/lib/private/appframework/http/dispatcher.php @@ -100,17 +100,15 @@ class Dispatcher { $response = $this->middlewareDispatcher->afterController( $controller, $methodName, $response); - // get the output which should be printed and run the after output - // middleware to modify the response - $output = $response->render(); - $out[3] = $this->middlewareDispatcher->beforeOutput( - $controller, $methodName, $output); - // depending on the cache object the headers need to be changed $out[0] = $this->protocol->getStatusHeader($response->getStatus(), $response->getLastModified(), $response->getETag()); $out[1] = array_merge($response->getHeaders()); $out[2] = $response->getCookies(); + $out[3] = $this->middlewareDispatcher->beforeOutput( + $controller, $methodName, $response->render() + ); + $out[4] = $response; return $out; } diff --git a/lib/private/appframework/http/output.php b/lib/private/appframework/http/output.php new file mode 100644 index 00000000000..808f1ec6dfd --- /dev/null +++ b/lib/private/appframework/http/output.php @@ -0,0 +1,70 @@ +<?php +/** + * @author Bernhard Posselt + * @copyright 2015 Bernhard Posselt <dev@bernhard-posselt.com> + * + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\AppFramework\Http; + +use OCP\AppFramework\Http\IOutput; + +/** + * Very thin wrapper class to make output testable + */ +class Output implements IOutput { + + /** + * @param string $out + */ + public function setOutput($out) { + print($out); + } + + /** + * @param string $path + * + * @return bool false if an error occured + */ + public function setReadfile($path) { + return @readfile($path); + } + + /** + * @param string $header + */ + public function setHeader($header) { + header($header); + } + + /** + * @param int $code sets the http status code + */ + public function setHttpResponseCode($code) { + http_response_code($code); + } + + /** + * @return int returns the current http response code + */ + public function getHttpResponseCode() { + return http_response_code(); + } + + /** + * @param string $name + * @param string $value + * @param int $expire + * @param string $path + * @param string $domain + * @param bool $secure + * @param bool $httponly + */ + public function setCookie($name, $value, $expire, $path, $domain, $secure, $httponly) { + setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); + } + +} |