Beispiel #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());
 }
Beispiel #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;
 }
Beispiel #3
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;
 }