Skip to content

Commit

Permalink
Support partitioned cookie (#999)
Browse files Browse the repository at this point in the history
* Support partitioned cookie

* Update SwooleClient.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
sy-records and taylorotwell authored Feb 18, 2025
1 parent 6da1f2f commit 1c5190c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/Swoole/SwooleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ public function sendResponseHeaders(Response $response, SwooleResponse $swooleRe
foreach ($response->headers->getCookies() as $cookie) {
$shouldDelete = (string) $cookie->getValue() === '';

$swooleResponse->{$cookie->isRaw() ? 'rawcookie' : 'cookie'}(
$method = $cookie->isRaw() ? 'rawcookie' : 'cookie';

$params = [
$cookie->getName(),
$shouldDelete ? 'deleted' : $cookie->getValue(),
$cookie->getExpiresTime(),
Expand All @@ -189,7 +191,14 @@ public function sendResponseHeaders(Response $response, SwooleResponse $swooleRe
$cookie->isSecure(),
$cookie->isHttpOnly(),
$cookie->getSameSite() ?? '',
);
];

if (extension_loaded('swoole') && SWOOLE_VERSION_ID >= 60000) {
$params[] = '';
$params[] = $cookie->isPartitioned();
}

$swooleResponse->$method(...$params);
}
}

Expand Down
9 changes: 7 additions & 2 deletions tests/SwooleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ public function test_respond_method_sends_response_to_swoole(): void
$swooleResponse->shouldReceive('header')->once()->with('Cache-Control', 'no-cache, private', true);
$swooleResponse->shouldReceive('header')->once()->with('Content-Type', 'text/html', true);
$swooleResponse->shouldReceive('header')->once()->with('Date', Mockery::type('string'), true);
$swooleResponse->shouldReceive('cookie')->once()->with('new', 'value', 0, '/', '', false, true, 'lax');
$swooleResponse->shouldReceive('cookie')->once()->with('cleared', 'deleted', Mockery::type('int'), '/', '', false, true, 'lax');
if (extension_loaded('swoole') && SWOOLE_VERSION_ID >= 60000) {
$swooleResponse->shouldReceive('cookie')->once()->with('new', 'value', 0, '/', '', false, true, 'lax', '', false);
$swooleResponse->shouldReceive('cookie')->once()->with('cleared', 'deleted', Mockery::type('int'), '/', '', false, true, 'lax', '', false);
} else {
$swooleResponse->shouldReceive('cookie')->once()->with('new', 'value', 0, '/', '', false, true, 'lax');
$swooleResponse->shouldReceive('cookie')->once()->with('cleared', 'deleted', Mockery::type('int'), '/', '', false, true, 'lax');
}
$swooleResponse->shouldReceive('write')->with('Hello World');
$swooleResponse->shouldReceive('end')->once();

Expand Down

0 comments on commit 1c5190c

Please sign in to comment.