Skip to content

Commit bd6bb1f

Browse files
committed
Log an error when setting a custom header on "Not Modified" responses
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 8506d08 commit bd6bb1f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/public/AppFramework/Http/Response.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
use OCP\AppFramework\Http;
4040
use OCP\AppFramework\Utility\ITimeFactory;
41+
use OCP\IConfig;
42+
use Psr\Log\LoggerInterface;
4143

4244
/**
4345
* Base class for responses. Also used to just send headers.
@@ -203,6 +205,18 @@ public function addHeader($name, $value) {
203205
// to be able to reliably check for security
204206
// headers
205207

208+
if (stripos($name, 'x-') === 0
209+
&& in_array($this->status, [Http::STATUS_NO_CONTENT, Http::STATUS_NOT_MODIFIED], true)) {
210+
/** @var IConfig $config */
211+
$config = \OC::$server->get(IConfig::class);
212+
213+
if ($config->getSystemValueBool('debug', false)) {
214+
\OC::$server->get(LoggerInterface::class)->error(
215+
'Setting a custom header on a 204 or 304 is not supported'
216+
);
217+
}
218+
}
219+
206220
if (is_null($value)) {
207221
unset($this->headers[$name]);
208222
} else {

0 commit comments

Comments
 (0)