Skip to content

Commit

Permalink
HttpExtension: added option 'disableNetteCookie' [Closes #205]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 25, 2021
1 parent 8f58187 commit 5777e50
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Bridges/HttpDI/HttpExtension.php
Expand Up @@ -43,6 +43,7 @@ public function getConfigSchema(): Nette\Schema\Schema
'cookiePath' => Expect::string(),
'cookieDomain' => Expect::string(),
'cookieSecure' => Expect::anyOf('auto', null, true, false)->firstIsDefault(), // Whether the cookie is available only through HTTPS
'disableNetteCookie' => Expect::bool(false), // disables cookie use by Nette
]);
}

Expand Down Expand Up @@ -133,10 +134,12 @@ private function sendHeaders()
}
}

$this->initialization->addBody(
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
[$this->prefix('request')]
);
if (!$config->disableNetteCookie) {
$this->initialization->addBody(
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
[$this->prefix('request')]
);
}
}


Expand Down
32 changes: 32 additions & 0 deletions tests/Http.DI/HttpExtension.sameSiteProtection.disabled.phpt
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

use Nette\Bridges\HttpDI\HttpExtension;
use Nette\DI;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';

if (PHP_SAPI === 'cli') {
Tester\Environment::skip('Headers are not testable in CLI mode');
}


$compiler = new DI\Compiler;
$compiler->addExtension('http', new HttpExtension);
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create(<<<'EOD'
http:
disableNetteCookie: yes
EOD
, 'neon'));

eval($compiler->addConfig($config)->compile());

$container = new Container;
$container->initialize();

$headers = headers_list();
Assert::notContains('Set-Cookie: _nss=1', implode('', $headers));

0 comments on commit 5777e50

Please sign in to comment.