Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/httpclient_headers_case' of https://github.com/s…
Browse files Browse the repository at this point in the history
…asezaki/zf2 into hotfix/http-headers-case
  • Loading branch information
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/Client/Adapter/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ public function setConfig($config = array())
}
}

/**
* Retrieve the array of all configuration options
*
* @return array
*/
/**
* Retrieve the array of all configuration options
*
* @return array
*/
public function getConfig()
{
return $this->config;
}

/**
/**
* Set the stream context for the TCP connection to the server
*
* Can accept either a pre-existing stream context resource, or an array
Expand Down Expand Up @@ -320,7 +320,7 @@ public function read()
if ($statusCode == 100 || $statusCode == 101) return $this->read();

// Check headers to see what kind of connection / transfer encoding we have
$headers = $responseObj->headers()->toArray();
$headers = $responseObj->headers();

/**
* Responses to HEAD requests and 204 or 304 responses are not expected
Expand All @@ -330,16 +330,19 @@ public function read()
$this->method == \Zend\Http\Request::METHOD_HEAD) {

// Close the connection if requested to do so by the server
if (isset($headers['connection']) && $headers['connection'] == 'close') {
$connection = $headers->get('connection');
if ($connection !== false && $connection->getFieldValue() == 'close') {
$this->close();
}
return $response;
}

// If we got a 'transfer-encoding: chunked' header
if (isset($headers['transfer-encoding'])) {
$transfer_encoding = $headers->get('transfer-encoding');
$content_length = $headers->get('content-length');
if ($transfer_encoding !== false) {

if (strtolower($headers['transfer-encoding']) == 'chunked') {
if (strtolower($transfer_encoding->getFieldValue()) == 'chunked') {

do {
$line = @fgets($this->socket);
Expand Down Expand Up @@ -390,7 +393,7 @@ public function read()
} else {
$this->close();
throw new AdapterException\RuntimeException('Cannot handle "' .
$headers['transfer-encoding'] . '" transfer encoding');
$transfer_encoding->getFieldValue() . '" transfer encoding');
}

// We automatically decode chunked-messages when writing to a stream
Expand All @@ -399,15 +402,14 @@ public function read()
$response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $response);
}
// Else, if we got the content-length header, read this number of bytes
} elseif (isset($headers['content-length'])) {
} elseif ($content_length !== false) {

// If we got more than one Content-Length header (see ZF-9404) use
// the last value sent
if (is_array($headers['content-length'])) {
$contentLength = $headers['content-length'][count($headers['content-length']) - 1];
} else {
$contentLength = $headers['content-length'];
if (is_array($content_length)) {
$content_length = $content_length[count($content_length) - 1];
}
$contentLength = $content_length->getFieldValue();

$current_pos = ftell($this->socket);
$chunk = '';
Expand Down Expand Up @@ -460,7 +462,8 @@ public function read()
}

// Close the connection if requested to do so by the server
if (isset($headers['connection']) && $headers['connection'] == 'close') {
$connection = $headers->get('connection');
if ($connection !== false && $connection->getFieldValue() == 'close') {
$this->close();
}

Expand Down

0 comments on commit aecd9f6

Please # to comment.