summaryrefslogtreecommitdiffstats
path: root/lib/public/appframework/http/response.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/appframework/http/response.php')
-rw-r--r--lib/public/appframework/http/response.php30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/public/appframework/http/response.php b/lib/public/appframework/http/response.php
index 67e72cff6d9..751c48b4ca9 100644
--- a/lib/public/appframework/http/response.php
+++ b/lib/public/appframework/http/response.php
@@ -72,6 +72,9 @@ class Response {
*/
private $ETag;
+ /** @var ContentSecurityPolicy|null Used Content-Security-Policy */
+ private $contentSecurityPolicy = null;
+
/**
* Caches the response
@@ -186,13 +189,19 @@ class Response {
* @return array the headers
*/
public function getHeaders() {
- $mergeWith = array();
+ $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 . '"';
}
@@ -221,6 +230,25 @@ class Response {
return $this;
}
+ /**
+ * Set a Content-Security-Policy
+ * @param ContentSecurityPolicy $csp Policy to set for the response object
+ * @return $this
+ */
+ 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.
+ */
+ public function getContentSecurityPolicy() {
+ return $this->contentSecurityPolicy;
+ }
+
/**
* Get response status