Skip to content

Commit 0dcea8b

Browse files
committed
Do not enforce the parent constructor of response to be called
If there is no policy set we just take the default empty ones. That way no obscure errors get thrown if the constructor is not called. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 0b0cdeb commit 0dcea8b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/public/AppFramework/Http/Response.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ class Response {
9292
/** @var array */
9393
private $throttleMetadata = [];
9494

95-
/**
96-
* Response constructor.
97-
*
98-
* @since 17.0.0
99-
*/
100-
public function __construct() {
101-
$this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
102-
$this->setFeaturePolicy(new EmptyFeaturePolicy());
103-
}
104-
10595
/**
10696
* Caches the response
10797
* @param int $cacheSeconds the amount of seconds that should be cached
@@ -241,12 +231,8 @@ public function getHeaders() {
241231
$this->lastModified->format(\DateTime::RFC2822);
242232
}
243233

244-
// Build Content-Security-Policy and use default if none has been specified
245-
if(is_null($this->contentSecurityPolicy)) {
246-
$this->setContentSecurityPolicy(new ContentSecurityPolicy());
247-
}
248-
$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
249-
$this->headers['Feature-Policy'] = $this->featurePolicy->buildPolicy();
234+
$this->headers['Content-Security-Policy'] = $this->getContentSecurityPolicy()->buildPolicy();
235+
$this->headers['Feature-Policy'] = $this->getFeaturePolicy()->buildPolicy();
250236

251237
if($this->ETag) {
252238
$mergeWith['ETag'] = '"' . $this->ETag . '"';
@@ -296,6 +282,9 @@ public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
296282
* @since 8.1.0
297283
*/
298284
public function getContentSecurityPolicy() {
285+
if ($this->contentSecurityPolicy === null) {
286+
$this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
287+
}
299288
return $this->contentSecurityPolicy;
300289
}
301290

@@ -304,6 +293,9 @@ public function getContentSecurityPolicy() {
304293
* @since 17.0.0
305294
*/
306295
public function getFeaturePolicy(): EmptyFeaturePolicy {
296+
if ($this->featurePolicy === null) {
297+
$this->setFeaturePolicy(new EmptyFeaturePolicy());
298+
}
307299
return $this->featurePolicy;
308300
}
309301

0 commit comments

Comments
 (0)