Skip to content

Commit

Permalink
Merge pull request #38 from 3aBXo3/develop
Browse files Browse the repository at this point in the history
Fix for #36 issue.
  • Loading branch information
tsivarev authored Dec 29, 2018
2 parents 12ef4cb + 0b48b82 commit 69a9448
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/VK/TransportClient/Curl/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function sendRequest(string $url, array $opts) {
curl_setopt_array($curl, $this->initial_opts + $opts);

$response = curl_exec($curl);
$curl_http_status_code = (int)curl_getinfo($curl, CURLINFO_RESPONSE_CODE);

$curl_error_code = curl_errno($curl);
$curl_error = curl_error($curl);
Expand All @@ -113,19 +114,20 @@ public function sendRequest(string $url, array $opts) {
throw new TransportRequestException($error_msg);
}

return $this->parseRawResponse($response);
return $this->parseRawResponse($response, $curl_http_status_code);
}

/**
* Breaks the raw response down into its headers, body and http status code.
* Breaks the raw response down into its headers, body.
*
* @param string $response
* @param int $http_status
*
* @return TransportClientResponse
*/
protected function parseRawResponse(string $response) {
protected function parseRawResponse(string $response, int $http_status) {
list($raw_headers, $body) = $this->extractResponseHeadersAndBody($response);
list($http_status, $headers) = $this->getHeaders($raw_headers);
$headers = $this->getHeaders($raw_headers);
return new TransportClientResponse($http_status, $headers, $body);
}

Expand Down Expand Up @@ -163,28 +165,13 @@ protected function getHeaders(string $raw_headers) {

$header_components = explode("\n", $raw_header);
$result = array();
$http_status = 0;
foreach ($header_components as $line) {
if (strpos($line, ': ') === false) {
$http_status = $this->getHttpStatus($line);
} else {
if (strpos($line, ': ') !== false) {
list($key, $value) = explode(': ', $line, 2);
$result[$key] = $value;
}
}

return array($http_status, $result);
}

/**
* Sets the HTTP response code from a raw header.
*
* @param string $raw_response_header
*
* @return int
*/
protected function getHttpStatus(string $raw_response_header): int {
preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $raw_response_header, $match);
return (int)$match[1];
return $result;
}
}

0 comments on commit 69a9448

Please sign in to comment.