Skip to content
Permalink
Browse files

Removed interference in the name of the headers.

  • Loading branch information...
jrbasso committed Nov 13, 2010
1 parent 44629bd commit 85607a9963ea375dc4d01bd098f8dbdcaa051f8b
Showing with 19 additions and 23 deletions.
  1. +12 −16 cake/libs/http_socket.php
  2. +7 −7 cake/tests/cases/libs/http_socket.test.php
@@ -864,6 +864,7 @@ protected function _httpSerialize($data = array()) {
* Builds the header.
*
* @param array $header Header to build
* @param string $mode
* @return string Header built from array
*/
protected function _buildHeader($header, $mode = 'standard') {
@@ -873,6 +874,17 @@ protected function _buildHeader($header, $mode = 'standard') {
return false;
}
$fieldsInHeader = array();
foreach ($header as $key => $value) {
$lowKey = strtolower($key);
if (array_key_exists($lowKey, $fieldsInHeader)) {
$header[$fieldsInHeader[$lowKey]] = $value;
unset($header[$key]);
} else {
$fieldsInHeader[$lowKey] = $key;
}
}
$returnHeader = '';
foreach ($header as $field => $contents) {
if (is_array($contents) && $mode == 'standard') {
@@ -896,16 +908,6 @@ protected function _buildHeader($header, $mode = 'standard') {
*/
protected function _parseHeader($header) {
if (is_array($header)) {
foreach ($header as $field => $value) {
unset($header[$field]);
$field = strtolower($field);
preg_match_all('/(?:^|(?<=-))[a-z]/U', $field, $offsets, PREG_OFFSET_CAPTURE);
foreach ($offsets[0] as $offset) {
$field = substr_replace($field, strtoupper($offset[0]), $offset[1], 1);
}
$header[$field] = $value;
}
return $header;
} elseif (!is_string($header)) {
return false;
@@ -922,12 +924,6 @@ protected function _parseHeader($header) {
$field = $this->_unescapeToken($field);
$field = strtolower($field);
preg_match_all('/(?:^|(?<=-))[a-z]/U', $field, $offsets, PREG_OFFSET_CAPTURE);
foreach ($offsets[0] as $offset) {
$field = substr_replace($field, strtoupper($offset[0]), $offset[1], 1);
}
if (!isset($header[$field])) {
$header[$field] = $value;
} else {
@@ -529,7 +529,7 @@ function testRequest() {
$expectation['request']['raw'] = $expectation['request']['line'].$expectation['request']['header']."\r\n".$raw;
$r = array('config' => $this->Socket->config, 'request' => $this->Socket->request);
$v = $this->assertEquals($r, $expectation, '%s in test #'.$i.' ');
$v = $this->assertEquals($r, $expectation, 'Failed test #'.$i.' ');
$expectation['request']['raw'] = $raw;
}
@@ -948,13 +948,13 @@ function testDecodeChunkedBody() {
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertEquals($r['body'], $decoded);
$this->assertEquals($r['header'], array('Foo-Header' => 'bar', 'Cake' => 'PHP'));
$this->assertEquals($r['header'], array('foo-header' => 'bar', 'cake' => 'PHP'));
$this->Socket->quirksMode = true;
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n";
$r = $this->Socket->decodeChunkedBody($encoded);
$this->assertEquals($r['body'], $decoded);
$this->assertEquals($r['header'], array('Foo-Header' => 'bar', 'Cake' => 'PHP'));
$this->assertEquals($r['header'], array('foo-header' => 'bar', 'cake' => 'PHP'));
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n";
$r = $this->Socket->decodeChunkedBody($encoded);
@@ -1393,7 +1393,7 @@ function testParseHeader() {
$this->Socket->reset();
$r = $this->Socket->parseHeader(array('foo' => 'Bar', 'fOO-bAr' => 'quux'));
$this->assertEquals($r, array('Foo' => 'Bar', 'Foo-Bar' => 'quux'));
$this->assertEquals($r, array('foo' => 'Bar', 'fOO-bAr' => 'quux'));
$r = $this->Socket->parseHeader(true);
$this->assertEquals($r, false);
@@ -1416,9 +1416,9 @@ function testParseHeader() {
$header = "people: Jim,John\r\nfoo-LAND: Bar\r\ncAKe-PHP: rocks\r\n";
$r = $this->Socket->parseHeader($header);
$expected = array(
'People' => 'Jim,John'
, 'Foo-Land' => 'Bar'
, 'Cake-Php' => 'rocks'
'people' => 'Jim,John'
, 'foo-LAND' => 'Bar'
, 'cAKe-PHP' => 'rocks'
);
$this->assertEquals($r, $expected);

0 comments on commit 85607a9

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