Skip to content

Commit 96a1c05

Browse files
committed
1 parent 944070e commit 96a1c05

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Http/Response.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,15 @@ public function __destruct()
233233
* @return static
234234
* @throws Nette\InvalidStateException if HTTP headers have been sent
235235
*/
236-
public function setCookie(string $name, string $value, $time, string $path = NULL, string $domain = NULL, bool $secure = NULL, bool $httpOnly = NULL)
236+
public function setCookie(string $name, string $value, $time, string $path = NULL, string $domain = NULL, bool $secure = NULL, bool $httpOnly = NULL, string $sameSite = NULL)
237237
{
238+
$sameSite = $sameSite ? "; SameSite=$sameSite" : '';
238239
self::checkHeaders();
239240
setcookie(
240241
$name,
241242
$value,
242243
$time ? (int) DateTime::from($time)->format('U') : 0,
243-
$path === NULL ? $this->cookiePath : $path,
244+
($path === NULL ? $this->cookiePath : $path) . $sameSite,
244245
$domain === NULL ? $this->cookieDomain : $domain,
245246
$secure === NULL ? $this->cookieSecure : $secure,
246247
$httpOnly === NULL ? $this->cookieHttpOnly : $httpOnly

tests/Http/Response.setCookie.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ $headers = array_values(array_diff(headers_list(), $old, ['Set-Cookie:']));
3333
Assert::same([
3434
'Set-Cookie: test=newvalue; path=/; HttpOnly',
3535
], $headers);
36+
37+
38+
$response->setCookie('test', 'newvalue', 0, NULL, NULL, NULL, NULL, 'Lax');
39+
$headers = array_values(array_diff(headers_list(), $old, ['Set-Cookie:']));
40+
Assert::same([
41+
'Set-Cookie: test=newvalue; path=/; SameSite=Lax; HttpOnly',
42+
], $headers);

0 commit comments

Comments
 (0)