mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Removed interference in the name of the headers.
This commit is contained in:
parent
44629bd673
commit
85607a9963
2 changed files with 19 additions and 23 deletions
|
@ -864,6 +864,7 @@ class HttpSocket extends CakeSocket {
|
|||
* 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 @@ class HttpSocket extends CakeSocket {
|
|||
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 @@ class HttpSocket extends CakeSocket {
|
|||
*/
|
||||
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 @@ class HttpSocket extends CakeSocket {
|
|||
|
||||
$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 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$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 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$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 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$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 @@ class HttpSocketTest extends CakeTestCase {
|
|||
$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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue