Skip to content

Commit

Permalink
fix #13
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed May 5, 2015
1 parent be1a951 commit b5de842
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Wechat/Utils/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ protected function request($url, $method = self::GET, $params = array(), $option
$response = $this->doCurl();

// Separate headers and body
$responseSplit = preg_split('/((?:\\r?\\n){2})/', $response['response']);
$responseCount = count($responseSplit);
$headerSize = $response['curl_info']['header_size'];
$header = substr($response['response'], 0, $headerSize);
$body = substr($response['response'], $headerSize);

$results = array(
'curl_info' => $response['curl_info'],
'content_type' => $response['curl_info']['content_type'],
'status' => $response['curl_info']['http_code'],
'headers' => count($responseSplit) > 2 ? $this->splitHeaders($responseSplit[$responseCount - 2]) : '' ,
'data' => count($responseSplit) > 1 ? $responseSplit[$responseCount - 1] : '',
'headers' => $this->splitHeaders($header),
'data' => $body,
);

return $results;
Expand Down Expand Up @@ -218,14 +219,16 @@ protected function createCurlFile($filename)
*/
protected function splitHeaders($rawHeaders)
{
$headers = array();
$headers = [];

$headerLines = explode("\n", $rawHeaders);
$headers['HTTP'] = array_shift($headerLines);

foreach ($headerLines as $line) {
$header = explode(':', $line, 2);
$headers[trim($header[0])] = trim($header[1]);
foreach (explode("\n", trim($rawHeaders)) as $i => $h) {
$h = explode(':', $h, 2);

if (isset($h[1])) {
$headers[$h[0]] = trim($h[1]);
}
}

return $headers;
Expand Down

0 comments on commit b5de842

Please sign in to comment.