예제 #1
0
 /**
  * Receive a response header from curl
  *
  * @param resource $curl   Curl handle
  * @param string   $header Received header
  *
  * @return int
  */
 public function receiveResponseHeader($curl, $header)
 {
     static $normalize = array("\r", "\n");
     $length = strlen($header);
     $header = str_replace($normalize, '', $header);
     if (strpos($header, 'HTTP/') === 0) {
         $startLine = explode(' ', $header, 3);
         $code = $startLine[1];
         $status = isset($startLine[2]) ? $startLine[2] : '';
         // Only download the body of the response to the specified response
         // body when a successful response is received.
         if ($code >= 200 && $code < 300) {
             $body = $this->request->getResponseBody();
         } else {
             $body = EntityBody::factory();
         }
         $response = new Response($code, null, $body);
         $response->setStatus($code, $status);
         $this->request->startResponse($response);
         $this->request->dispatch('request.receive.status_line', array('request' => $this, 'line' => $header, 'status_code' => $code, 'reason_phrase' => $status));
     } elseif ($pos = strpos($header, ':')) {
         $this->request->getResponse()->addHeader(trim(substr($header, 0, $pos)), trim(substr($header, $pos + 1)));
     }
     return $length;
 }