Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions lib/Mage/HTTP/Client/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,29 @@ public function doError($string)
* Parse headers - CURL callback functin
*
* @param resource $ch curl handle, not needed
* @param string $data
* @param string $data
*
* @return int
*/
protected function parseHeaders($ch, $data)
protected function parseHeaders($ch, $data): int
{
if($this->_headerCount == 0) {
if ($this->_headerCount === 0) {
$line = explode(' ', trim($data), 3);

$line = explode(" ", trim($data), 3);
if(count($line) != 3) {
return $this->doError("Invalid response line returned from server: ".$data);
}
$this->_responseStatus = intval($line[1]);
$this->validateHttpVersion($line);
$this->_responseStatus = (int)$line[1];
} else {
//var_dump($data);
$name = $value = '';
$out = explode(": ", trim($data), 2);
if(count($out) == 2) {
$name = $out[0];
$value = $out[1];
$out = explode(': ', trim($data), 2);
if (count($out) === 2) {
list($name, $value) = $out;
}

if(strlen($name)) {
if("Set-Cookie" == $name) {
if(!isset($this->_responseHeaders[$name])) {
$this->_responseHeaders[$name] = array();
if ($name !== '') {
if ($name === 'Set-Cookie') {
if (!isset($this->_responseHeaders[$name])) {
$this->_responseHeaders[$name] = [];
}
$this->_responseHeaders[$name][] = $value;
} else {
Expand All @@ -456,10 +454,34 @@ protected function parseHeaders($ch, $data)
}
$this->_headerCount++;


return strlen($data);
}

/**
* @param array $line
*
* @throws Exception
*/
protected function validateHttpVersion(array $line)
{
if ($line[0] === 'HTTP/1.0' || $line[0] === 'HTTP/1.1') {
if (count($line) !== 3) {
$this->doError('Invalid response line returned from server: ' . implode(' ', $line));
}

return;
}

if ($line[0] === 'HTTP/2') {
if (!in_array(count($line), [2, 3])) {
$this->doError('Invalid response line returned from server: ' . implode(' ', $line));
}

return;
}
$this->doError('Invalid response line returned from server: ' . $data);
}

/**
* Set curl option directly
*
Expand Down