From 1c5190cc5ad67eb4aadbf1816dcbfedc692851e7 Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Tue, 18 Feb 2025 23:18:13 +0800 Subject: [PATCH] Support partitioned cookie (#999) * Support partitioned cookie * Update SwooleClient.php --------- Co-authored-by: Taylor Otwell --- src/Swoole/SwooleClient.php | 13 +++++++++++-- tests/SwooleClientTest.php | 9 +++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Swoole/SwooleClient.php b/src/Swoole/SwooleClient.php index 486d129af..58a205342 100644 --- a/src/Swoole/SwooleClient.php +++ b/src/Swoole/SwooleClient.php @@ -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(), @@ -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); } } diff --git a/tests/SwooleClientTest.php b/tests/SwooleClientTest.php index 00ce72da4..687ff9caa 100644 --- a/tests/SwooleClientTest.php +++ b/tests/SwooleClientTest.php @@ -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();