Skip to content

Commit

Permalink
HttpExtension: sends headers via Http\Response
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 19, 2016
1 parent 71602f2 commit 0221544
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Bridges/HttpDI/HttpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
} elseif (preg_match('#^https?:#', $frames)) {
$frames = "ALLOW-FROM $frames";
}
$initialize->addBody('header(?);', ["X-Frame-Options: $frames"]);
$initialize->addBody('$this->getService(?)->setHeader(?, ?);', [$this->prefix('response'), 'X-Frame-Options', $frames]);
}

foreach ($config['headers'] as $key => $value) {
if ($value != NULL) { // intentionally ==
$initialize->addBody('header(?);', ["$key: $value"]);
$initialize->addBody('$this->getService(?)->setHeader(?, ?);', [$this->prefix('response'), $key, $value]);
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions tests/Http.DI/HttpExtension.headers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ echo ' '; @ob_flush(); flush();

Assert::true(headers_sent());

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

0 comments on commit 0221544

Please sign in to comment.