-
Notifications
You must be signed in to change notification settings - Fork 36
Use Swoole parsed cookies again #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,19 @@ public function setUp(): void | |
| $this->client = new Client('http://swoole'); | ||
| } | ||
|
|
||
| public function testCookie(): void | ||
| { | ||
| $headers = ['Cookie: cookie1=value1; cookie2=value2']; | ||
|
|
||
| $response = $this->client->call(Client::METHOD_GET, '/cookie/cookie1', $headers); | ||
| $this->assertEquals(200, $response['headers']['status-code']); | ||
| $this->assertEquals('value1', $response['body']); | ||
|
|
||
| $response = $this->client->call(Client::METHOD_GET, '/cookie/cookie2', $headers); | ||
| $this->assertEquals(200, $response['headers']['status-code']); | ||
| $this->assertEquals('value2', $response['body']); | ||
| } | ||
|
Comment on lines
+19
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since the whole point of this PR is to restore Swoole native cookie parsing, it would be valuable to confirm Swoole handles at least the Consider adding a test case such as: $response = $this->client->call(
Client::METHOD_GET,
'/cookie/cookie1',
['Cookie: cookie1=value1=value2']
);
$this->assertEquals('value1=value2', $response['body']); |
||
|
|
||
| public function testSwooleResources(): void | ||
| { | ||
| $response = $this->client->call(Client::METHOD_DELETE, '/swoole-test'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCookie()key normalisation differs from FPM adapterSwoole's native cookie parser stores cookie names in lowercase (all HTTP header keys are lowercased by Swoole), so the
strtolower($key)here correctly normalises lookup. However,FPM\Request::getCookie()performs no such normalisation — it looks up$_COOKIE[$key]with the key exactly as passed.This means
getCookie('MyToken')returns the cookie on Swoole (lowercased lookup matchesmytoken) but will miss it on FPM when the cookie was sent asmytoken. The reverse is also true: FPM is case-sensitive while Swoole is case-insensitive. Any application that callsgetCookie()with a mixed-case cookie name will behave differently depending on the adapter in use.This is a pre-existing 0.33.x characteristic being restored, but it may be worth documenting the difference or adding a note to
getCookie()'s docblock so callers know to use lowercase keys for portability across adapters.