Skip to content

Commit 5777e50

Browse files
committed
HttpExtension: added option 'disableNetteCookie' [Closes #205]
1 parent 8f58187 commit 5777e50

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
@@ -43,6 +43,7 @@ public function getConfigSchema(): Nette\Schema\Schema
4343
'cookiePath' => Expect::string(),
4444
'cookieDomain' => Expect::string(),
4545
'cookieSecure' => Expect::anyOf('auto', null, true, false)->firstIsDefault(), // Whether the cookie is available only through HTTPS
46+
'disableNetteCookie' => Expect::bool(false), // disables cookie use by Nette
4647
]);
4748
}
4849

@@ -133,10 +134,12 @@ private function sendHeaders()
133134
}
134135
}
135136

136-
$this->initialization->addBody(
137-
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
138-
[$this->prefix('request')]
139-
);
137+
if (!$config->disableNetteCookie) {
138+
$this->initialization->addBody(
139+
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
140+
[$this->prefix('request')]
141+
);
142+
}
140143
}
141144

142145

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: _nss=1', implode('', $headers));

0 commit comments

Comments
 (0)