Skip to content

Commit

Permalink
Fixed cookie parsing, parse_str replaces urlencoded characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
akotulu committed Oct 9, 2024
1 parent d36eed3 commit 9a95978
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Protocols/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,17 @@ public function setHeaders(array $headers): Request
public function cookie(string $name = null, mixed $default = null): mixed
{
if (!isset($this->data['cookie'])) {
$this->data['cookie'] = [];
parse_str(preg_replace('/; ?/', '&', $this->header('cookie', '')), $this->data['cookie']);
$cookies = explode(';', $this->header('cookie', ''));
$mapped = array();

foreach ($cookies as $cookie) {
$cookie = explode('=', $cookie);
if (count($cookie) !== 2) {
continue;
}
$mapped[trim($cookie[0])] = $cookie[1];
}
$this->data['cookie'] = $mapped;
}
if ($name === null) {
return $this->data['cookie'];
Expand Down

0 comments on commit 9a95978

Please sign in to comment.