Skip to content
Permalink
Browse files

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
  • Loading branch information...
markstory committed Apr 19, 2013
1 parent d01d291 commit 4d8dd124491d1f16b4dd3ad056a2acd760b31f4d
Showing with 9 additions and 3 deletions.
  1. +6 −1 lib/Cake/Network/Http/HttpSocket.php
  2. +3 −2 lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
@@ -942,7 +942,12 @@ protected function _buildHeader($header, $mode = 'standard') {
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');
}
@@ -1590,9 +1590,10 @@ public function testBuildCookies() {
'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);
}

0 comments on commit 4d8dd12

Please sign in to comment.
You can’t perform that action at this time.