protected function LingotekOAuthRequester::curl_parse in Lingotek Translation 7.7
Same name and namespace in other branches
- 7.4 lib/oauth-php/library/LingotekOAuthRequester.php \LingotekOAuthRequester::curl_parse()
- 7.5 lib/oauth-php/library/LingotekOAuthRequester.php \LingotekOAuthRequester::curl_parse()
- 7.6 lib/oauth-php/library/LingotekOAuthRequester.php \LingotekOAuthRequester::curl_parse()
* Parse an http response * *
Parameters
string response the http text to parse: * @return array (code=>http-code, headers=>http-headers, body=>body)
1 call to LingotekOAuthRequester::curl_parse()
- LingotekOAuthRequester::doRequest in lib/
oauth-php/ library/ LingotekOAuthRequester.php - * Perform the request, returns the response code, headers and body. * *
File
- lib/
oauth-php/ library/ LingotekOAuthRequester.php, line 451
Class
Code
protected function curl_parse($response) {
if (empty($response)) {
return array();
}
@(list($headers, $body) = explode("\r\n\r\n", $response, 2));
$lines = explode("\r\n", $headers);
while (preg_match('@^HTTP/[0-9]\\.?[0-9]? +100@', $lines[0]) || preg_match('@^HTTP/[0-9]\\.?[0-9]? +200 +Connection established@', $lines[0])) {
/* HTTP/1.x 100 Continue or HTTP/1.x 200 Connection established
* the real data is on the next line
*/
@(list($headers, $body) = explode("\r\n\r\n", $body, 2));
$lines = explode("\r\n", $headers);
}
// first line of headers is the HTTP response code
$http_line = array_shift($lines);
if (preg_match('@^HTTP/[0-9]\\.?[0-9]? +([0-9]{3})@', $http_line, $matches)) {
$code = $matches[1];
}
// put the rest of the headers in an array
$headers = array();
foreach ($lines as $l) {
list($k, $v) = explode(': ', $l, 2);
$headers[strtolower($k)] = $v;
}
return array(
'code' => $code,
'headers' => $headers,
'body' => $body,
);
}