Skip to content

Commit 3ef562b

Browse files
committed
CurlClient: response headers are extracted by CURLINFO_HEADER_SIZE [Closes #5]
1 parent b67dd1b commit 3ef562b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/Github/Http/CurlClient.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,20 @@ protected function process(Request $request)
8989
if ($result === FALSE) {
9090
throw new BadResponseException(curl_error($this->curl), curl_errno($this->curl));
9191
}
92-
list($headersStr, $content) = explode("\r\n\r\n", $result, 2) + ['', ''];
92+
93+
$headersLength = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
94+
if ($headersLength === FALSE) {
95+
throw new BadResponseException(curl_error($this->curl), curl_errno($this->curl));
96+
}
9397

9498
$code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
9599
if ($code === FALSE) {
96-
throw new BadResponseException('HTTP status code is missing.');
100+
throw new BadResponseException('HTTP status code is missing:' . curl_error($this->curl), curl_errno($this->curl));
97101
}
98102

103+
$headersStr = trim(substr($result, 0, $headersLength));
104+
$content = (string) substr($result, $headersLength);
105+
99106
$headers = [];
100107
foreach (array_slice(explode("\r\n", $headersStr), 1) as $header) {
101108
list($name, $value) = explode(': ', $header);

0 commit comments

Comments
 (0)