Skip to content

Commit

Permalink
Added support for HTTP2 to Mage_HTTP_Client_Curl (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schrank authored Aug 3, 2022
1 parent 35acb46 commit 7f352b6
Showing 1 changed file with 39 additions and 17 deletions.
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

0 comments on commit 7f352b6

Please sign in to comment.