Skip to content

Commit d22f102

Browse files
committed
HttpExtension: added option 'disableNetteCookie' [Closes #205]
1 parent 302783e commit d22f102

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/Bridges/HttpDI/HttpExtension.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function getConfigSchema(): Nette\Schema\Schema
4141
'cspReportOnly' => Expect::arrayOf('array|scalar|null'), // Content-Security-Policy-Report-Only
4242
'featurePolicy' => Expect::arrayOf('array|scalar|null'), // Feature-Policy
4343
'cookieSecure' => Expect::anyOf(null, true, false, 'auto'), // true|false|auto Whether the cookie is available only through HTTPS
44+
'disableNetteCookie' => Expect::bool(false), // disables cookie use by Nette
4445
]);
4546
}
4647

@@ -120,10 +121,12 @@ private function sendHeaders()
120121
}
121122
}
122123

123-
$this->initialization->addBody(
124-
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
125-
[$this->prefix('request')]
126-
);
124+
if (!$config->disableNetteCookie) {
125+
$this->initialization->addBody(
126+
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
127+
[$this->prefix('request')]
128+
);
129+
}
127130
}
128131

129132

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nette\Bridges\HttpDI\HttpExtension;
6+
use Nette\DI;
7+
use Tester\Assert;
8+
9+
10+
require __DIR__ . '/../bootstrap.php';
11+
12+
if (PHP_SAPI === 'cli') {
13+
Tester\Environment::skip('Headers are not testable in CLI mode');
14+
}
15+
16+
17+
$compiler = new DI\Compiler;
18+
$compiler->addExtension('http', new HttpExtension);
19+
$loader = new DI\Config\Loader;
20+
$config = $loader->load(Tester\FileMock::create(<<<'EOD'
21+
http:
22+
disableNetteCookie: yes
23+
EOD
24+
, 'neon'));
25+
26+
eval($compiler->addConfig($config)->compile());
27+
28+
$container = new Container;
29+
$container->initialize();
30+
31+
$headers = headers_list();
32+
Assert::notContains('Set-Cookie: nette-samesite=1', implode('', $headers));

0 commit comments

Comments
 (0)