Skip to content

Commit 0221544

Browse files
committed
HttpExtension: sends headers via Http\Response
1 parent 71602f2 commit 0221544

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/Bridges/HttpDI/HttpExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
7979
} elseif (preg_match('#^https?:#', $frames)) {
8080
$frames = "ALLOW-FROM $frames";
8181
}
82-
$initialize->addBody('header(?);', ["X-Frame-Options: $frames"]);
82+
$initialize->addBody('$this->getService(?)->setHeader(?, ?);', [$this->prefix('response'), 'X-Frame-Options', $frames]);
8383
}
8484

8585
foreach ($config['headers'] as $key => $value) {
8686
if ($value != NULL) { // intentionally ==
87-
$initialize->addBody('header(?);', ["$key: $value"]);
87+
$initialize->addBody('$this->getService(?)->setHeader(?, ?);', [$this->prefix('response'), $key, $value]);
8888
}
8989
}
9090
}

tests/Http.DI/HttpExtension.headers.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ echo ' '; @ob_flush(); flush();
4444

4545
Assert::true(headers_sent());
4646

47-
Assert::error(function () use ($container) {
47+
Assert::exception(function () use ($container) {
4848
$container->initialize();
49-
}, [
50-
[E_WARNING, 'Cannot modify header information - headers already sent %a%'],
51-
[E_WARNING, 'Cannot modify header information - headers already sent %a%'],
52-
[E_WARNING, 'Cannot modify header information - headers already sent %a%'],
53-
[E_WARNING, 'Cannot modify header information - headers already sent %a%'],
54-
]);
49+
}, Nette\InvalidStateException::class, 'Cannot send header after %a%');

0 commit comments

Comments
 (0)