Exemplo n.º 1
0
 private static function parse_response($raw, $info)
 {
     list($head, $body) = explode("\r\n\r\n", $raw, 2);
     list($head_out, $body_out) = explode("\r\n\r\n", $info['request_header'], 2);
     unset($info['request_header']);
     $headers_in = SlackHTTP::parse_headers($head, '_status');
     $headers_out = SlackHTTP::parse_headers($head_out, '_request');
     preg_match("/^([A-Z]+)\\s/", $headers_out['_request'], $m);
     $method = $m[1];
     # log_notice("http", "{$method} {$url}", $end-$start);
     # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2
     # http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success (note HTTP 207 WTF)
     $status = $info['http_code'];
     if ($status < 200 || $status > 299) {
         return array('ok' => false, 'error' => 'http_failed', 'code' => $info['http_code'], 'method' => $method, 'url' => $info['url'], 'info' => $info, 'req_headers' => $headers_out, 'headers' => $headers_in, 'body' => $body);
     }
     return array('ok' => true, 'code' => $info['http_code'], 'method' => $method, 'url' => $info['url'], 'info' => $info, 'req_headers' => $headers_out, 'headers' => $headers_in, 'body' => $body);
 }