Ejemplo n.º 1
0
 /**
  * @dataProvider provideRawResponse
  */
 public function testSetRawResponse($raw, $status, $headers, $body)
 {
     $response = new Response();
     $response->setRawResponse($raw);
     if (null !== $status) {
         $this->assertEquals($status, $response->getStatus()->getStatus());
     }
     if (null !== $headers) {
         foreach ($headers as $key => $value) {
             $header = $response->getHeader($key);
             $this->assertNotNull($header);
             $this->assertEquals($key, $header->getName());
             $this->assertEquals($value, $header->getValue());
         }
     }
     $this->assertEquals($body, $response->getBody());
 }
Ejemplo n.º 2
0
 /**
  * Write request
  * @return \Nimbles\Http\Client\Response
  */
 public function write()
 {
     $curlOptions = array_merge($this->_defaultCurlOptions, $this->getCurlOptions());
     $curlOptions[CURLOPT_URL] = $this->_request->getRequestUri();
     $curlOptions[CURLOPT_CUSTOMREQUEST] = $this->_request->getMethod();
     $curlOptions[CURLOPT_RETURNTRANSFER] = true;
     $curlOptions[CURLOPT_HEADER] = true;
     $ch = curl_init();
     curl_setopt_array($ch, $curlOptions);
     if (!($result = curl_exec($ch))) {
         throw new Curl\Exception(curl_error($ch));
     }
     curl_close($ch);
     $response = new Client\Response();
     $response->setRawResponse($result);
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * Set the last successful response
  * @param \Nimbles\Http\Client\Response $request
  * @return \Nimbles\Http\Client
  */
 protected function _setLastResponse(Client\Response $response)
 {
     if (null !== $response->getCookie() && 0 < $response->getCookie()->count() && null !== ($cookieJar = $this->getCookieJar())) {
         $cookieJar->setCookies($response->getCookie()->getArrayCopy());
     }
     $this->_lastResponse = $response;
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Write request
  * @return \Nimbles\Http\Client\Response
  */
 public function write()
 {
     $curlOptions = array_merge($this->_defaultCurlOptions, $this->getCurlOptions());
     $curlOptions[CURLOPT_RETURNTRANSFER] = true;
     $curlOptions[CURLOPT_HEADER] = true;
     $multiHandle = curl_multi_init();
     $arrayOfHandles = array();
     foreach ($this->_requests as $request) {
         $curlOptions[CURLOPT_URL] = $request->getRequestUri();
         $curlOptions[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
         $curlHandle = curl_init();
         curl_setopt_array($curlHandle, $curlOptions);
         curl_multi_add_handle($multiHandle, $curlHandle);
         $arrayOfHandles[(int) $curlHandle] = $request;
     }
     $running = null;
     do {
         usleep(1000);
         curl_multi_exec($multiHandle, $running);
     } while ($running > 0);
     $responses = array();
     while ($curlData = curl_multi_info_read($multiHandle)) {
         $request = $arrayOfHandles[(int) $curlData['handle']];
         $result = curl_multi_getcontent($curlData['handle']);
         $response = new Client\Response();
         $response->setRawResponse($result);
         $responses[] = array('request' => $request, 'response' => $response);
     }
     return $responses;
 }