예제 #1
0
 /**
  * @param resource $ch cURL handler
  *
  * @return Response
  */
 public function createResponse($ch)
 {
     if (!$this->request->getUrl()) {
         throw new \InvalidArgumentException('Request url is empty.');
     }
     $resourceId = (int) $ch;
     $info = curl_getinfo($ch);
     $reasonPhrase = ResponseUtils::getReasonPhrase($info['http_code']);
     $errorNo = isset($ch['result']) ? $ch['result'] : curl_errno($ch);
     $response = new Response();
     $response->setStatusCode($info['http_code'])->setReasonPhrase($reasonPhrase)->setRequestUrl($this->request->getUrl())->setEffectiveUrl($info['url'])->setContentType($info['content_type'])->setErrorMsg(curl_error($ch))->setErrorNumber($errorNo)->setBody(curl_multi_getcontent($ch));
     if (isset($this->headers[$resourceId])) {
         $headersSet = explode("\n\n", trim($this->headers[$resourceId]));
         $this->parseResponseHeaders($response, array_pop($headersSet));
         $response->setStatusCode($info['http_code'])->setReasonPhrase($reasonPhrase);
         // Set redirects
         foreach ($headersSet as $headers) {
             $redirect = new Redirect();
             $this->parseResponseHeaders($redirect, $headers);
             $response->addRedirect($redirect);
         }
     }
     // Set curl info
     foreach ($this->unusedInfoKeys as $key) {
         unset($info[$key]);
     }
     $response->setCurlInfo($info);
     return $response;
 }
예제 #2
0
파일: Client.php 프로젝트: arturdoruch/http
 /**
  * @param Request $request
  * @param array   $curlOptions
  *
  * @return Response
  */
 public function request(Request $request, array $curlOptions = array())
 {
     $this->validateUrl($request->getUrl());
     $handler = new RequestHandler($request);
     $this->options->prepareOptions($handler, $curlOptions);
     $responses = $this->sendRequest($handler);
     return $this->lastResponse = $responses[0];
 }