aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/AppFramework/Http
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-05-06 20:38:34 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2016-05-06 20:38:34 +0200
commite47b186d5117b56eb73a9d6c6f95d4d78ddd6084 (patch)
treece9a2b4feb3a3e77b4849eba768a22ba0d8ba924 /lib/public/AppFramework/Http
parent09c507246d6795eb389c2b97af5db0200800637e (diff)
downloadnextcloud-server-e47b186d5117b56eb73a9d6c6f95d4d78ddd6084.tar.gz
nextcloud-server-e47b186d5117b56eb73a9d6c6f95d4d78ddd6084.zip
Move \OCP\AppFramework to PSR-4
Diffstat (limited to 'lib/public/AppFramework/Http')
-rw-r--r--lib/public/AppFramework/Http/ContentSecurityPolicy.php88
-rw-r--r--lib/public/AppFramework/Http/DataDisplayResponse.php88
-rw-r--r--lib/public/AppFramework/Http/DataDownloadResponse.php63
-rw-r--r--lib/public/AppFramework/Http/DataResponse.php83
-rw-r--r--lib/public/AppFramework/Http/DownloadResponse.php52
-rw-r--r--lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php385
-rw-r--r--lib/public/AppFramework/Http/ICallbackResponse.php43
-rw-r--r--lib/public/AppFramework/Http/IOutput.php77
-rw-r--r--lib/public/AppFramework/Http/JSONResponse.php100
-rw-r--r--lib/public/AppFramework/Http/NotFoundResponse.php49
-rw-r--r--lib/public/AppFramework/Http/OCSResponse.php91
-rw-r--r--lib/public/AppFramework/Http/RedirectResponse.php61
-rw-r--r--lib/public/AppFramework/Http/Response.php326
-rw-r--r--lib/public/AppFramework/Http/StreamResponse.php64
-rw-r--r--lib/public/AppFramework/Http/TemplateResponse.php159
15 files changed, 1729 insertions, 0 deletions
diff --git a/lib/public/AppFramework/Http/ContentSecurityPolicy.php b/lib/public/AppFramework/Http/ContentSecurityPolicy.php
new file mode 100644
index 00000000000..7762ca809a2
--- /dev/null
+++ b/lib/public/AppFramework/Http/ContentSecurityPolicy.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author sualko <klaus@jsxc.org>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * Class ContentSecurityPolicy is a simple helper which allows applications to
+ * modify the Content-Security-Policy sent by ownCloud. Per default only JavaScript,
+ * stylesheets, images, fonts, media and connections from the same domain
+ * ('self') are allowed.
+ *
+ * Even if a value gets modified above defaults will still get appended. Please
+ * notice that ownCloud ships already with sensible defaults and those policies
+ * should require no modification at all for most use-cases.
+ *
+ * @package OCP\AppFramework\Http
+ * @since 8.1.0
+ */
+class ContentSecurityPolicy extends EmptyContentSecurityPolicy {
+ /** @var bool Whether inline JS snippets are allowed */
+ protected $inlineScriptAllowed = false;
+ /**
+ * @var bool Whether eval in JS scripts is allowed
+ * TODO: Disallow per default
+ * @link https://github.com/owncloud/core/issues/11925
+ */
+ protected $evalScriptAllowed = true;
+ /** @var array Domains from which scripts can get loaded */
+ protected $allowedScriptDomains = [
+ '\'self\'',
+ ];
+ /**
+ * @var bool Whether inline CSS is allowed
+ * TODO: Disallow per default
+ * @link https://github.com/owncloud/core/issues/13458
+ */
+ protected $inlineStyleAllowed = true;
+ /** @var array Domains from which CSS can get loaded */
+ protected $allowedStyleDomains = [
+ '\'self\'',
+ ];
+ /** @var array Domains from which images can get loaded */
+ protected $allowedImageDomains = [
+ '\'self\'',
+ 'data:',
+ 'blob:',
+ ];
+ /** @var array Domains to which connections can be done */
+ protected $allowedConnectDomains = [
+ '\'self\'',
+ ];
+ /** @var array Domains from which media elements can be loaded */
+ protected $allowedMediaDomains = [
+ '\'self\'',
+ ];
+ /** @var array Domains from which object elements can be loaded */
+ protected $allowedObjectDomains = [];
+ /** @var array Domains from which iframes can be loaded */
+ protected $allowedFrameDomains = [];
+ /** @var array Domains from which fonts can be loaded */
+ protected $allowedFontDomains = [
+ '\'self\'',
+ ];
+ /** @var array Domains from which web-workers and nested browsing content can load elements */
+ protected $allowedChildSrcDomains = [];
+}
diff --git a/lib/public/AppFramework/Http/DataDisplayResponse.php b/lib/public/AppFramework/Http/DataDisplayResponse.php
new file mode 100644
index 00000000000..4209c86a059
--- /dev/null
+++ b/lib/public/AppFramework/Http/DataDisplayResponse.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * Class DataDisplayResponse
+ *
+ * @package OCP\AppFramework\Http
+ * @since 8.1.0
+ */
+class DataDisplayResponse extends Response {
+
+ /**
+ * response data
+ * @var string;
+ */
+ protected $data;
+
+
+ /**
+ * @param string $data the data to display
+ * @param int $statusCode the Http status code, defaults to 200
+ * @param array $headers additional key value based headers
+ * @since 8.1.0
+ */
+ public function __construct($data="", $statusCode=Http::STATUS_OK,
+ $headers=[]) {
+ $this->data = $data;
+ $this->setStatus($statusCode);
+ $this->setHeaders(array_merge($this->getHeaders(), $headers));
+ $this->addHeader('Content-Disposition', 'inline; filename=""');
+ }
+
+ /**
+ * Outputs data. No processing is done.
+ * @return string
+ * @since 8.1.0
+ */
+ public function render() {
+ return $this->data;
+ }
+
+
+ /**
+ * Sets values in the data
+ * @param string $data the data to display
+ * @return DataDisplayResponse Reference to this object
+ * @since 8.1.0
+ */
+ public function setData($data){
+ $this->data = $data;
+
+ return $this;
+ }
+
+
+ /**
+ * Used to get the set parameters
+ * @return string the data
+ * @since 8.1.0
+ */
+ public function getData(){
+ return $this->data;
+ }
+
+}
diff --git a/lib/public/AppFramework/Http/DataDownloadResponse.php b/lib/public/AppFramework/Http/DataDownloadResponse.php
new file mode 100644
index 00000000000..55ef4e6c82c
--- /dev/null
+++ b/lib/public/AppFramework/Http/DataDownloadResponse.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @author Georg Ehrke <georg@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OCP\AppFramework\Http;
+
+/**
+ * Class DataDownloadResponse
+ *
+ * @package OCP\AppFramework\Http
+ * @since 8.0.0
+ */
+class DataDownloadResponse extends DownloadResponse {
+ /**
+ * @var string
+ */
+ private $data;
+
+ /**
+ * Creates a response that prompts the user to download the text
+ * @param string $data text to be downloaded
+ * @param string $filename the name that the downloaded file should have
+ * @param string $contentType the mimetype that the downloaded file should have
+ * @since 8.0.0
+ */
+ public function __construct($data, $filename, $contentType) {
+ $this->data = $data;
+ parent::__construct($filename, $contentType);
+ }
+
+ /**
+ * @param string $data
+ * @since 8.0.0
+ */
+ public function setData($data) {
+ $this->data = $data;
+ }
+
+ /**
+ * @return string
+ * @since 8.0.0
+ */
+ public function render() {
+ return $this->data;
+ }
+}
diff --git a/lib/public/AppFramework/Http/DataResponse.php b/lib/public/AppFramework/Http/DataResponse.php
new file mode 100644
index 00000000000..3ec4e2bdc32
--- /dev/null
+++ b/lib/public/AppFramework/Http/DataResponse.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * AppFramework\HTTP\DataResponse class
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * A generic DataResponse class that is used to return generic data responses
+ * for responders to transform
+ * @since 8.0.0
+ */
+class DataResponse extends Response {
+
+ /**
+ * response data
+ * @var array|object
+ */
+ protected $data;
+
+
+ /**
+ * @param array|object $data the object or array that should be transformed
+ * @param int $statusCode the Http status code, defaults to 200
+ * @param array $headers additional key value based headers
+ * @since 8.0.0
+ */
+ public function __construct($data=array(), $statusCode=Http::STATUS_OK,
+ array $headers=array()) {
+ $this->data = $data;
+ $this->setStatus($statusCode);
+ $this->setHeaders(array_merge($this->getHeaders(), $headers));
+ }
+
+
+ /**
+ * Sets values in the data json array
+ * @param array|object $data an array or object which will be transformed
+ * @return DataResponse Reference to this object
+ * @since 8.0.0
+ */
+ public function setData($data){
+ $this->data = $data;
+
+ return $this;
+ }
+
+
+ /**
+ * Used to get the set parameters
+ * @return array the data
+ * @since 8.0.0
+ */
+ public function getData(){
+ return $this->data;
+ }
+
+
+}
diff --git a/lib/public/AppFramework/Http/DownloadResponse.php b/lib/public/AppFramework/Http/DownloadResponse.php
new file mode 100644
index 00000000000..af0d76951ca
--- /dev/null
+++ b/lib/public/AppFramework/Http/DownloadResponse.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OCP\AppFramework\Http;
+
+
+/**
+ * Prompts the user to download the a file
+ * @since 7.0.0
+ */
+class DownloadResponse extends \OCP\AppFramework\Http\Response {
+
+ private $filename;
+ private $contentType;
+
+ /**
+ * Creates a response that prompts the user to download the file
+ * @param string $filename the name that the downloaded file should have
+ * @param string $contentType the mimetype that the downloaded file should have
+ * @since 7.0.0
+ */
+ public function __construct($filename, $contentType) {
+ $this->filename = $filename;
+ $this->contentType = $contentType;
+
+ $this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
+ $this->addHeader('Content-Type', $contentType);
+ }
+
+
+}
diff --git a/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php b/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php
new file mode 100644
index 00000000000..61718ff7c0e
--- /dev/null
+++ b/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php
@@ -0,0 +1,385 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * Class EmptyContentSecurityPolicy is a simple helper which allows applications
+ * to modify the Content-Security-Policy sent by ownCloud. Per default the policy
+ * is forbidding everything.
+ *
+ * As alternative with sane exemptions look at ContentSecurityPolicy
+ *
+ * @see \OCP\AppFramework\Http\ContentSecurityPolicy
+ * @package OCP\AppFramework\Http
+ * @since 9.0.0
+ */
+class EmptyContentSecurityPolicy {
+ /** @var bool Whether inline JS snippets are allowed */
+ protected $inlineScriptAllowed = null;
+ /**
+ * @var bool Whether eval in JS scripts is allowed
+ * TODO: Disallow per default
+ * @link https://github.com/owncloud/core/issues/11925
+ */
+ protected $evalScriptAllowed = null;
+ /** @var array Domains from which scripts can get loaded */
+ protected $allowedScriptDomains = null;
+ /**
+ * @var bool Whether inline CSS is allowed
+ * TODO: Disallow per default
+ * @link https://github.com/owncloud/core/issues/13458
+ */
+ protected $inlineStyleAllowed = null;
+ /** @var array Domains from which CSS can get loaded */
+ protected $allowedStyleDomains = null;
+ /** @var array Domains from which images can get loaded */
+ protected $allowedImageDomains = null;
+ /** @var array Domains to which connections can be done */
+ protected $allowedConnectDomains = null;
+ /** @var array Domains from which media elements can be loaded */
+ protected $allowedMediaDomains = null;
+ /** @var array Domains from which object elements can be loaded */
+ protected $allowedObjectDomains = null;
+ /** @var array Domains from which iframes can be loaded */
+ protected $allowedFrameDomains = null;
+ /** @var array Domains from which fonts can be loaded */
+ protected $allowedFontDomains = null;
+ /** @var array Domains from which web-workers and nested browsing content can load elements */
+ protected $allowedChildSrcDomains = null;
+
+ /**
+ * Whether inline JavaScript snippets are allowed or forbidden
+ * @param bool $state
+ * @return $this
+ * @since 8.1.0
+ */
+ public function allowInlineScript($state = false) {
+ $this->inlineScriptAllowed = $state;
+ return $this;
+ }
+
+ /**
+ * Whether eval in JavaScript is allowed or forbidden
+ * @param bool $state
+ * @return $this
+ * @since 8.1.0
+ */
+ public function allowEvalScript($state = true) {
+ $this->evalScriptAllowed = $state;
+ return $this;
+ }
+
+ /**
+ * Allows to execute JavaScript files from a specific domain. Use * to
+ * allow JavaScript from all domains.
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedScriptDomain($domain) {
+ $this->allowedScriptDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed script domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowScriptDomain($domain) {
+ $this->allowedScriptDomains = array_diff($this->allowedScriptDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * Whether inline CSS snippets are allowed or forbidden
+ * @param bool $state
+ * @return $this
+ * @since 8.1.0
+ */
+ public function allowInlineStyle($state = true) {
+ $this->inlineStyleAllowed = $state;
+ return $this;
+ }
+
+ /**
+ * Allows to execute CSS files from a specific domain. Use * to allow
+ * CSS from all domains.
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedStyleDomain($domain) {
+ $this->allowedStyleDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed style domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowStyleDomain($domain) {
+ $this->allowedStyleDomains = array_diff($this->allowedStyleDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * Allows using fonts from a specific domain. Use * to allow
+ * fonts from all domains.
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedFontDomain($domain) {
+ $this->allowedFontDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed font domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowFontDomain($domain) {
+ $this->allowedFontDomains = array_diff($this->allowedFontDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * Allows embedding images from a specific domain. Use * to allow
+ * images from all domains.
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedImageDomain($domain) {
+ $this->allowedImageDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed image domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowImageDomain($domain) {
+ $this->allowedImageDomains = array_diff($this->allowedImageDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * To which remote domains the JS connect to.
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedConnectDomain($domain) {
+ $this->allowedConnectDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed connect domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowConnectDomain($domain) {
+ $this->allowedConnectDomains = array_diff($this->allowedConnectDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * From which domains media elements can be embedded.
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedMediaDomain($domain) {
+ $this->allowedMediaDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed media domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowMediaDomain($domain) {
+ $this->allowedMediaDomains = array_diff($this->allowedMediaDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * From which domains objects such as <object>, <embed> or <applet> are executed
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedObjectDomain($domain) {
+ $this->allowedObjectDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed object domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowObjectDomain($domain) {
+ $this->allowedObjectDomains = array_diff($this->allowedObjectDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * Which domains can be embedded in an iframe
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedFrameDomain($domain) {
+ $this->allowedFrameDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed frame domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowFrameDomain($domain) {
+ $this->allowedFrameDomains = array_diff($this->allowedFrameDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * Domains from which web-workers and nested browsing content can load elements
+ * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized.
+ * @return $this
+ * @since 8.1.0
+ */
+ public function addAllowedChildSrcDomain($domain) {
+ $this->allowedChildSrcDomains[] = $domain;
+ return $this;
+ }
+
+ /**
+ * Remove the specified allowed child src domain from the allowed domains.
+ *
+ * @param string $domain
+ * @return $this
+ * @since 8.1.0
+ */
+ public function disallowChildSrcDomain($domain) {
+ $this->allowedChildSrcDomains = array_diff($this->allowedChildSrcDomains, [$domain]);
+ return $this;
+ }
+
+ /**
+ * Get the generated Content-Security-Policy as a string
+ * @return string
+ * @since 8.1.0
+ */
+ public function buildPolicy() {
+ $policy = "default-src 'none';";
+
+ if(!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) {
+ $policy .= 'script-src ';
+ if(is_array($this->allowedScriptDomains)) {
+ $policy .= implode(' ', $this->allowedScriptDomains);
+ }
+ if($this->inlineScriptAllowed) {
+ $policy .= ' \'unsafe-inline\'';
+ }
+ if($this->evalScriptAllowed) {
+ $policy .= ' \'unsafe-eval\'';
+ }
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedStyleDomains) || $this->inlineStyleAllowed) {
+ $policy .= 'style-src ';
+ if(is_array($this->allowedStyleDomains)) {
+ $policy .= implode(' ', $this->allowedStyleDomains);
+ }
+ if($this->inlineStyleAllowed) {
+ $policy .= ' \'unsafe-inline\'';
+ }
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedImageDomains)) {
+ $policy .= 'img-src ' . implode(' ', $this->allowedImageDomains);
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedFontDomains)) {
+ $policy .= 'font-src ' . implode(' ', $this->allowedFontDomains);
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedConnectDomains)) {
+ $policy .= 'connect-src ' . implode(' ', $this->allowedConnectDomains);
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedMediaDomains)) {
+ $policy .= 'media-src ' . implode(' ', $this->allowedMediaDomains);
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedObjectDomains)) {
+ $policy .= 'object-src ' . implode(' ', $this->allowedObjectDomains);
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedFrameDomains)) {
+ $policy .= 'frame-src ' . implode(' ', $this->allowedFrameDomains);
+ $policy .= ';';
+ }
+
+ if(!empty($this->allowedChildSrcDomains)) {
+ $policy .= 'child-src ' . implode(' ', $this->allowedChildSrcDomains);
+ $policy .= ';';
+ }
+
+ return rtrim($policy, ';');
+ }
+}
diff --git a/lib/public/AppFramework/Http/ICallbackResponse.php b/lib/public/AppFramework/Http/ICallbackResponse.php
new file mode 100644
index 00000000000..97de484e917
--- /dev/null
+++ b/lib/public/AppFramework/Http/ICallbackResponse.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\AppFramework\Http;
+
+
+/**
+ * Interface ICallbackResponse
+ *
+ * @package OCP\AppFramework\Http
+ * @since 8.1.0
+ */
+interface ICallbackResponse {
+
+ /**
+ * Outputs the content that should be printed
+ *
+ * @param IOutput $output a small wrapper that handles output
+ * @since 8.1.0
+ */
+ function callback(IOutput $output);
+
+}
diff --git a/lib/public/AppFramework/Http/IOutput.php b/lib/public/AppFramework/Http/IOutput.php
new file mode 100644
index 00000000000..6c404c0b026
--- /dev/null
+++ b/lib/public/AppFramework/Http/IOutput.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\AppFramework\Http;
+
+
+/**
+ * Very thin wrapper class to make output testable
+ * @since 8.1.0
+ */
+interface IOutput {
+
+ /**
+ * @param string $out
+ * @since 8.1.0
+ */
+ public function setOutput($out);
+
+ /**
+ * @param string $path
+ *
+ * @return bool false if an error occurred
+ * @since 8.1.0
+ */
+ public function setReadfile($path);
+
+ /**
+ * @param string $header
+ * @since 8.1.0
+ */
+ public function setHeader($header);
+
+ /**
+ * @return int returns the current http response code
+ * @since 8.1.0
+ */
+ public function getHttpResponseCode();
+
+ /**
+ * @param int $code sets the http status code
+ * @since 8.1.0
+ */
+ public function setHttpResponseCode($code);
+
+ /**
+ * @param string $name
+ * @param string $value
+ * @param int $expire
+ * @param string $path
+ * @param string $domain
+ * @param bool $secure
+ * @param bool $httpOnly
+ * @since 8.1.0
+ */
+ public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
+
+}
diff --git a/lib/public/AppFramework/Http/JSONResponse.php b/lib/public/AppFramework/Http/JSONResponse.php
new file mode 100644
index 00000000000..89433fd23e5
--- /dev/null
+++ b/lib/public/AppFramework/Http/JSONResponse.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Thomas Tanghus <thomas@tanghus.net>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * AppFramework\HTTP\JSONResponse class
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * A renderer for JSON calls
+ * @since 6.0.0
+ */
+class JSONResponse extends Response {
+
+ /**
+ * response data
+ * @var array|object
+ */
+ protected $data;
+
+
+ /**
+ * constructor of JSONResponse
+ * @param array|object $data the object or array that should be transformed
+ * @param int $statusCode the Http status code, defaults to 200
+ * @since 6.0.0
+ */
+ public function __construct($data=array(), $statusCode=Http::STATUS_OK) {
+ $this->data = $data;
+ $this->setStatus($statusCode);
+ $this->addHeader('Content-Type', 'application/json; charset=utf-8');
+ }
+
+
+ /**
+ * Returns the rendered json
+ * @return string the rendered json
+ * @since 6.0.0
+ * @throws \Exception If data could not get encoded
+ */
+ public function render() {
+ $response = json_encode($this->data, JSON_HEX_TAG);
+ if($response === false) {
+ throw new \Exception(sprintf('Could not json_encode due to invalid ' .
+ 'non UTF-8 characters in the array: %s', var_export($this->data, true)));
+ }
+
+ return $response;
+ }
+
+ /**
+ * Sets values in the data json array
+ * @param array|object $data an array or object which will be transformed
+ * to JSON
+ * @return JSONResponse Reference to this object
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function setData($data){
+ $this->data = $data;
+
+ return $this;
+ }
+
+
+ /**
+ * Used to get the set parameters
+ * @return array the data
+ * @since 6.0.0
+ */
+ public function getData(){
+ return $this->data;
+ }
+
+}
diff --git a/lib/public/AppFramework/Http/NotFoundResponse.php b/lib/public/AppFramework/Http/NotFoundResponse.php
new file mode 100644
index 00000000000..8dcebd7cceb
--- /dev/null
+++ b/lib/public/AppFramework/Http/NotFoundResponse.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+use OCP\Template;
+
+/**
+ * A generic 404 response showing an 404 error page as well to the end-user
+ * @since 8.1.0
+ */
+class NotFoundResponse extends Response {
+
+ /**
+ * @since 8.1.0
+ */
+ public function __construct() {
+ $this->setStatus(404);
+ }
+
+ /**
+ * @return string
+ * @since 8.1.0
+ */
+ public function render() {
+ $template = new Template('core', '404', 'guest');
+ return $template->fetchPage();
+ }
+}
diff --git a/lib/public/AppFramework/Http/OCSResponse.php b/lib/public/AppFramework/Http/OCSResponse.php
new file mode 100644
index 00000000000..da9de712c0a
--- /dev/null
+++ b/lib/public/AppFramework/Http/OCSResponse.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * AppFramework\HTTP\JSONResponse class
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * A renderer for OCS responses
+ * @since 8.1.0
+ */
+class OCSResponse extends Response {
+
+ private $data;
+ private $format;
+ private $statuscode;
+ private $message;
+ private $itemscount;
+ private $itemsperpage;
+
+ /**
+ * generates the xml or json response for the API call from an multidimenional data array.
+ * @param string $format
+ * @param int $statuscode
+ * @param string $message
+ * @param array $data
+ * @param int|string $itemscount
+ * @param int|string $itemsperpage
+ * @since 8.1.0
+ */
+ public function __construct($format, $statuscode, $message,
+ $data=[], $itemscount='',
+ $itemsperpage='') {
+ $this->format = $format;
+ $this->statuscode = $statuscode;
+ $this->message = $message;
+ $this->data = $data;
+ $this->itemscount = $itemscount;
+ $this->itemsperpage = $itemsperpage;
+
+ // set the correct header based on the format parameter
+ if ($format === 'json') {
+ $this->addHeader(
+ 'Content-Type', 'application/json; charset=utf-8'
+ );
+ } else {
+ $this->addHeader(
+ 'Content-Type', 'application/xml; charset=utf-8'
+ );
+ }
+ }
+
+ /**
+ * @return string
+ * @since 8.1.0
+ */
+ public function render() {
+ $r = new \OC_OCS_Result($this->data, $this->statuscode, $this->message);
+ $r->setTotalItems($this->itemscount);
+ $r->setItemsPerPage($this->itemsperpage);
+
+ return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
+ }
+
+
+}
diff --git a/lib/public/AppFramework/Http/RedirectResponse.php b/lib/public/AppFramework/Http/RedirectResponse.php
new file mode 100644
index 00000000000..97140c9955f
--- /dev/null
+++ b/lib/public/AppFramework/Http/RedirectResponse.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author v1r0x <vinzenz.rosenkranz@gmail.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http\Response;
+use OCP\AppFramework\Http;
+
+
+/**
+ * Redirects to a different URL
+ * @since 7.0.0
+ */
+class RedirectResponse extends Response {
+
+ private $redirectURL;
+
+ /**
+ * Creates a response that redirects to a url
+ * @param string $redirectURL the url to redirect to
+ * @since 7.0.0
+ */
+ public function __construct($redirectURL) {
+ $this->redirectURL = $redirectURL;
+ $this->setStatus(Http::STATUS_SEE_OTHER);
+ $this->addHeader('Location', $redirectURL);
+ }
+
+
+ /**
+ * @return string the url to redirect
+ * @since 7.0.0
+ */
+ public function getRedirectURL() {
+ return $this->redirectURL;
+ }
+
+
+}
diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php
new file mode 100644
index 00000000000..253d58b86ff
--- /dev/null
+++ b/lib/public/AppFramework/Http/Response.php
@@ -0,0 +1,326 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Thomas Tanghus <thomas@tanghus.net>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * AppFramework\HTTP\Response class
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * Base class for responses. Also used to just send headers.
+ *
+ * It handles headers, HTTP status code, last modified and ETag.
+ * @since 6.0.0
+ */
+class Response {
+
+ /**
+ * Headers - defaults to ['Cache-Control' => 'no-cache, must-revalidate']
+ * @var array
+ */
+ private $headers = array(
+ 'Cache-Control' => 'no-cache, must-revalidate'
+ );
+
+
+ /**
+ * Cookies that will be need to be constructed as header
+ * @var array
+ */
+ private $cookies = array();
+
+
+ /**
+ * HTTP status code - defaults to STATUS OK
+ * @var int
+ */
+ private $status = Http::STATUS_OK;
+
+
+ /**
+ * Last modified date
+ * @var \DateTime
+ */
+ private $lastModified;
+
+
+ /**
+ * ETag
+ * @var string
+ */
+ private $ETag;
+
+ /** @var ContentSecurityPolicy|null Used Content-Security-Policy */
+ private $contentSecurityPolicy = null;
+
+
+ /**
+ * Caches the response
+ * @param int $cacheSeconds the amount of seconds that should be cached
+ * if 0 then caching will be disabled
+ * @return $this
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function cacheFor($cacheSeconds) {
+
+ if($cacheSeconds > 0) {
+ $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds .
+ ', must-revalidate');
+ } else {
+ $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
+ }
+
+ return $this;
+ }
+
+ /**
+ * Adds a new cookie to the response
+ * @param string $name The name of the cookie
+ * @param string $value The value of the cookie
+ * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
+ * to null cookie will be considered as session
+ * cookie.
+ * @return $this
+ * @since 8.0.0
+ */
+ public function addCookie($name, $value, \DateTime $expireDate = null) {
+ $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
+ return $this;
+ }
+
+
+ /**
+ * Set the specified cookies
+ * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
+ * @return $this
+ * @since 8.0.0
+ */
+ public function setCookies(array $cookies) {
+ $this->cookies = $cookies;
+ return $this;
+ }
+
+
+ /**
+ * Invalidates the specified cookie
+ * @param string $name
+ * @return $this
+ * @since 8.0.0
+ */
+ public function invalidateCookie($name) {
+ $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
+ return $this;
+ }
+
+ /**
+ * Invalidates the specified cookies
+ * @param array $cookieNames array('foo', 'bar')
+ * @return $this
+ * @since 8.0.0
+ */
+ public function invalidateCookies(array $cookieNames) {
+ foreach($cookieNames as $cookieName) {
+ $this->invalidateCookie($cookieName);
+ }
+ return $this;
+ }
+
+ /**
+ * Returns the cookies
+ * @return array
+ * @since 8.0.0
+ */
+ public function getCookies() {
+ return $this->cookies;
+ }
+
+ /**
+ * Adds a new header to the response that will be called before the render
+ * function
+ * @param string $name The name of the HTTP header
+ * @param string $value The value, null will delete it
+ * @return $this
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function addHeader($name, $value) {
+ $name = trim($name); // always remove leading and trailing whitespace
+ // to be able to reliably check for security
+ // headers
+
+ if(is_null($value)) {
+ unset($this->headers[$name]);
+ } else {
+ $this->headers[$name] = $value;
+ }
+
+ return $this;
+ }
+
+
+ /**
+ * Set the headers
+ * @param array $headers value header pairs
+ * @return $this
+ * @since 8.0.0
+ */
+ public function setHeaders(array $headers) {
+ $this->headers = $headers;
+
+ return $this;
+ }
+
+
+ /**
+ * Returns the set headers
+ * @return array the headers
+ * @since 6.0.0
+ */
+ public function getHeaders() {
+ $mergeWith = [];
+
+ if($this->lastModified) {
+ $mergeWith['Last-Modified'] =
+ $this->lastModified->format(\DateTime::RFC2822);
+ }
+
+ // Build Content-Security-Policy and use default if none has been specified
+ if(is_null($this->contentSecurityPolicy)) {
+ $this->setContentSecurityPolicy(new ContentSecurityPolicy());
+ }
+ $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
+
+ if($this->ETag) {
+ $mergeWith['ETag'] = '"' . $this->ETag . '"';
+ }
+
+ return array_merge($mergeWith, $this->headers);
+ }
+
+
+ /**
+ * By default renders no output
+ * @return null
+ * @since 6.0.0
+ */
+ public function render() {
+ return null;
+ }
+
+
+ /**
+ * Set response status
+ * @param int $status a HTTP status code, see also the STATUS constants
+ * @return Response Reference to this object
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function setStatus($status) {
+ $this->status = $status;
+
+ return $this;
+ }
+
+ /**
+ * Set a Content-Security-Policy
+ * @param ContentSecurityPolicy $csp Policy to set for the response object
+ * @return $this
+ * @since 8.1.0
+ */
+ public function setContentSecurityPolicy(ContentSecurityPolicy $csp) {
+ $this->contentSecurityPolicy = $csp;
+ return $this;
+ }
+
+ /**
+ * Get the currently used Content-Security-Policy
+ * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if
+ * none specified.
+ * @since 8.1.0
+ */
+ public function getContentSecurityPolicy() {
+ return $this->contentSecurityPolicy;
+ }
+
+
+ /**
+ * Get response status
+ * @since 6.0.0
+ */
+ public function getStatus() {
+ return $this->status;
+ }
+
+
+ /**
+ * Get the ETag
+ * @return string the etag
+ * @since 6.0.0
+ */
+ public function getETag() {
+ return $this->ETag;
+ }
+
+
+ /**
+ * Get "last modified" date
+ * @return \DateTime RFC2822 formatted last modified date
+ * @since 6.0.0
+ */
+ public function getLastModified() {
+ return $this->lastModified;
+ }
+
+
+ /**
+ * Set the ETag
+ * @param string $ETag
+ * @return Response Reference to this object
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function setETag($ETag) {
+ $this->ETag = $ETag;
+
+ return $this;
+ }
+
+
+ /**
+ * Set "last modified" date
+ * @param \DateTime $lastModified
+ * @return Response Reference to this object
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function setLastModified($lastModified) {
+ $this->lastModified = $lastModified;
+
+ return $this;
+ }
+
+
+}
diff --git a/lib/public/AppFramework/Http/StreamResponse.php b/lib/public/AppFramework/Http/StreamResponse.php
new file mode 100644
index 00000000000..e9157f9ddb2
--- /dev/null
+++ b/lib/public/AppFramework/Http/StreamResponse.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\AppFramework\Http;
+
+use OCP\AppFramework\Http;
+
+/**
+ * Class StreamResponse
+ *
+ * @package OCP\AppFramework\Http
+ * @since 8.1.0
+ */
+class StreamResponse extends Response implements ICallbackResponse {
+ /** @var string */
+ private $filePath;
+
+ /**
+ * @param string $filePath the path to the file which should be streamed
+ * @since 8.1.0
+ */
+ public function __construct ($filePath) {
+ $this->filePath = $filePath;
+ }
+
+
+ /**
+ * Streams the file using readfile
+ *
+ * @param IOutput $output a small wrapper that handles output
+ * @since 8.1.0
+ */
+ public function callback (IOutput $output) {
+ // handle caching
+ if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
+ if (!file_exists($this->filePath)) {
+ $output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
+ } elseif ($output->setReadfile($this->filePath) === false) {
+ $output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
+ }
+ }
+ }
+
+}
diff --git a/lib/public/AppFramework/Http/TemplateResponse.php b/lib/public/AppFramework/Http/TemplateResponse.php
new file mode 100644
index 00000000000..7774d881e4d
--- /dev/null
+++ b/lib/public/AppFramework/Http/TemplateResponse.php
@@ -0,0 +1,159 @@
+<?php
+/**
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Thomas Tanghus <thomas@tanghus.net>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * AppFramework\HTTP\TemplateResponse class
+ */
+
+namespace OCP\AppFramework\Http;
+
+
+/**
+ * Response for a normal template
+ * @since 6.0.0
+ */
+class TemplateResponse extends Response {
+
+ /**
+ * name of the template
+ * @var string
+ */
+ protected $templateName;
+
+ /**
+ * parameters
+ * @var array
+ */
+ protected $params;
+
+ /**
+ * rendering type (admin, user, blank)
+ * @var string
+ */
+ protected $renderAs;
+
+ /**
+ * app name
+ * @var string
+ */
+ protected $appName;
+
+ /**
+ * constructor of TemplateResponse
+ * @param string $appName the name of the app to load the template from
+ * @param string $templateName the name of the template
+ * @param array $params an array of parameters which should be passed to the
+ * template
+ * @param string $renderAs how the page should be rendered, defaults to user
+ * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0
+ */
+ public function __construct($appName, $templateName, array $params=array(),
+ $renderAs='user') {
+ $this->templateName = $templateName;
+ $this->appName = $appName;
+ $this->params = $params;
+ $this->renderAs = $renderAs;
+ }
+
+
+ /**
+ * Sets template parameters
+ * @param array $params an array with key => value structure which sets template
+ * variables
+ * @return TemplateResponse Reference to this object
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function setParams(array $params){
+ $this->params = $params;
+
+ return $this;
+ }
+
+
+ /**
+ * Used for accessing the set parameters
+ * @return array the params
+ * @since 6.0.0
+ */
+ public function getParams(){
+ return $this->params;
+ }
+
+
+ /**
+ * Used for accessing the name of the set template
+ * @return string the name of the used template
+ * @since 6.0.0
+ */
+ public function getTemplateName(){
+ return $this->templateName;
+ }
+
+
+ /**
+ * Sets the template page
+ * @param string $renderAs admin, user or blank. Admin also prints the admin
+ * settings header and footer, user renders the normal
+ * normal page including footer and header and blank
+ * just renders the plain template
+ * @return TemplateResponse Reference to this object
+ * @since 6.0.0 - return value was added in 7.0.0
+ */
+ public function renderAs($renderAs){
+ $this->renderAs = $renderAs;
+
+ return $this;
+ }
+
+
+ /**
+ * Returns the set renderAs
+ * @return string the renderAs value
+ * @since 6.0.0
+ */
+ public function getRenderAs(){
+ return $this->renderAs;
+ }
+
+
+ /**
+ * Returns the rendered html
+ * @return string the rendered html
+ * @since 6.0.0
+ */
+ public function render(){
+ // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
+ $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
+
+ $template = new \OCP\Template($this->appName, $this->templateName, $renderAs);
+
+ foreach($this->params as $key => $value){
+ $template->assign($key, $value);
+ }
+
+ return $template->fetchPage();
+ }
+
+}