summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2014-11-28 10:16:22 +0100
committerMorris Jobke <hey@morrisjobke.de>2014-11-28 10:16:22 +0100
commitb188710af33fde461a57e81dfc4aaf1cf7c6fda5 (patch)
tree3d66021b2507fc28e887b5c4b647a65ae11ef654 /lib/private
parent7a9af8c40c4ff2c2005a304a6474e9f328a3be5c (diff)
parente35feadac2ed68f0aad911713cb3d5f8725707e6 (diff)
downloadnextcloud-server-b188710af33fde461a57e81dfc4aaf1cf7c6fda5.tar.gz
nextcloud-server-b188710af33fde461a57e81dfc4aaf1cf7c6fda5.zip
Merge pull request #12472 from owncloud/modifyCookies
Add functions to modify cookies to response class
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/appframework/app.php10
-rw-r--r--lib/private/appframework/http/dispatcher.php8
-rw-r--r--lib/private/server.php28
3 files changed, 36 insertions, 10 deletions
diff --git a/lib/private/appframework/app.php b/lib/private/appframework/app.php
index baf52d02054..f56ba4af870 100644
--- a/lib/private/appframework/app.php
+++ b/lib/private/appframework/app.php
@@ -53,7 +53,7 @@ class App {
// initialize the dispatcher and run all the middleware before the controller
$dispatcher = $container['Dispatcher'];
- list($httpHeaders, $responseHeaders, $output) =
+ list($httpHeaders, $responseHeaders, $responseCookies, $output) =
$dispatcher->dispatch($controller, $methodName);
if(!is_null($httpHeaders)) {
@@ -64,6 +64,14 @@ class App {
header($name . ': ' . $value);
}
+ foreach($responseCookies as $name => $value) {
+ $expireDate = null;
+ if($value['expireDate'] instanceof \DateTime) {
+ $expireDate = $value['expireDate']->getTimestamp();
+ }
+ setcookie($name, $value['value'], $expireDate, $container->getServer()->getWebRoot(), null, $container->getServer()->getConfig()->getSystemValue('forcessl', false), true);
+ }
+
if(!is_null($output)) {
header('Content-Length: ' . strlen($output));
print($output);
diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php
index 29a661d5743..24540ef3c94 100644
--- a/lib/private/appframework/http/dispatcher.php
+++ b/lib/private/appframework/http/dispatcher.php
@@ -48,7 +48,7 @@ class Dispatcher {
* @param Http $protocol the http protocol with contains all status headers
* @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which
* runs the middleware
- * @param ControllerMethodReflector the reflector that is used to inject
+ * @param ControllerMethodReflector $reflector the reflector that is used to inject
* the arguments for the controller
* @param IRequest $request the incoming request
*/
@@ -71,6 +71,7 @@ class Dispatcher {
* @return array $array[0] contains a string with the http main header,
* $array[1] contains headers in the form: $key => value, $array[2] contains
* the response output
+ * @throws \Exception
*/
public function dispatch(Controller $controller, $methodName) {
$out = array(null, array(), null);
@@ -102,13 +103,14 @@ class Dispatcher {
// get the output which should be printed and run the after output
// middleware to modify the response
$output = $response->render();
- $out[2] = $this->middlewareDispatcher->beforeOutput(
+ $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] = $response->getHeaders();
+ $out[1] = array_merge($response->getHeaders());
+ $out[2] = $response->getCookies();
return $out;
}
diff --git a/lib/private/server.php b/lib/private/server.php
index cd57d41ce58..7bd7f8ca45d 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -29,19 +29,27 @@ use OC\Tagging\TagMapper;
* TODO: hookup all manager classes
*/
class Server extends SimpleContainer implements IServerContainer {
- function __construct() {
+ /** @var string */
+ private $webRoot;
+
+ /**
+ * @param string $webRoot
+ */
+ function __construct($webRoot) {
+ $this->webRoot = $webRoot;
+
$this->registerService('ContactsManager', function ($c) {
return new ContactsManager();
});
- $this->registerService('Request', function ($c) {
+ $this->registerService('Request', function (Server $c) {
if (isset($c['urlParams'])) {
$urlParams = $c['urlParams'];
} else {
$urlParams = array();
}
- if (\OC::$server->getSession()->exists('requesttoken')) {
- $requestToken = \OC::$server->getSession()->get('requesttoken');
+ if ($c->getSession()->exists('requesttoken')) {
+ $requestToken = $c->getSession()->get('requesttoken');
} else {
$requestToken = false;
}
@@ -233,8 +241,7 @@ class Server extends SimpleContainer implements IServerContainer {
return new NullQueryLogger();
}
});
- $this->registerService('TempManager', function ($c) {
- /** @var Server $c */
+ $this->registerService('TempManager', function (Server $c) {
return new TempManager(get_temp_dir(), $c->getLogger());
});
$this->registerService('AppManager', function(Server $c) {
@@ -631,4 +638,13 @@ class Server extends SimpleContainer implements IServerContainer {
function getAppManager() {
return $this->query('AppManager');
}
+
+ /**
+ * Get the webroot
+ *
+ * @return string
+ */
+ function getWebRoot() {
+ return $this->webRoot;
+ }
}