From 4d8dd124491d1f16b4dd3ad056a2acd760b31f4d Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 18 Apr 2013 21:22:50 -0400 Subject: [PATCH] Add support for key => value cookies. This makes using simple arrays easier, and I feel it is a long standing omission from HttpSocket. Fixes #3771 --- lib/Cake/Network/Http/HttpSocket.php | 7 ++++++- lib/Cake/Test/Case/Network/Http/HttpSocketTest.php | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index e8a36ba9b..ebebad62c 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -942,7 +942,12 @@ class HttpSocket extends CakeSocket { public function buildCookies($cookies) { $header = array(); foreach ($cookies as $name => $cookie) { - $header[] = $name . '=' . $this->_escapeToken($cookie['value'], array(';')); + if (is_array($cookie)) { + $value = $this->_escapeToken($cookie['value'], array(';')); + } else { + $value = $this->_escapeToken($cookie, array(';')); + } + $header[] = $name . '=' . $value; } return $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic'); } diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index b1ffa5c84..88d07e315 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php @@ -1590,9 +1590,10 @@ class HttpSocketTest extends CakeTestCase { 'people' => array( 'value' => 'jim,jack,johnny;', 'path' => '/accounts' - ) + ), + 'key' => 'value' ); - $expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"\r\n"; + $expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"; key=value\r\n"; $result = $this->Socket->buildCookies($cookies); $this->assertEquals($expect, $result); }