You are here

protected function OAuthRequester::curl_parse in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.2 lib/oauth-php/library/OAuthRequester.php \OAuthRequester::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 OAuthRequester::curl_parse()
OAuthRequester::doRequest in lib/oauth-php/library/OAuthRequester.php
* Perform the request, returns the response code, headers and body. * *

File

lib/oauth-php/library/OAuthRequester.php, line 451

Class

OAuthRequester

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);
  if (preg_match('@^HTTP/[0-9]\\.[0-9] +100@', $lines[0])) {

    /* HTTP/1.x 100 Continue
     * 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,
  );
}