/**
  * @covers Guzzle\Http\Curl\CurlMulti
  */
 public function testRemovesQueuedRequests()
 {
     $request = RequestFactory::getInstance()->create('GET', 'http://127.0.0.1:9876/');
     $request->setClient(new Client());
     $request->setResponse(new Response(200), true);
     $this->multi->add($request);
     $this->multi->send();
     $this->assertTrue($this->mock->has(CurlMulti::ADD_REQUEST));
     $this->assertTrue($this->mock->has(CurlMulti::POLLING) === false);
     $this->assertTrue($this->mock->has(CurlMulti::COMPLETE) !== false);
 }
 public function testRequestBeforeSendIncludesContentLengthHeaderIfEmptyBody()
 {
     $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
     $request = new Request('PUT', $this->getServer()->getUrl());
     $that = $this;
     $request->getEventDispatcher()->addListener('request.before_send', function ($event) use($that) {
         $that->assertEquals(0, $event['request']->getHeader('Content-Length'));
     });
     $this->multi->add($request);
     $this->multi->send();
 }
Beispiel #3
0
 protected function getAvailableHandle()
 {
     foreach ($this->handles as $h) {
         if (!in_array($h, $this->groups, true)) {
             return $h;
         }
     }
     $handle = new CurlMulti();
     $handle->setEventDispatcher($this->getEventDispatcher());
     $this->handles[] = $handle;
     return $handle;
 }
 /**
  * @covers Guzzle\Http\Curl\CurlMulti::reset
  */
 public function testHardResetReopensMultiHandle()
 {
     $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
     $client = new Client($this->getServer()->getUrl());
     $message = '';
     $plugin = new LogPlugin(new ClosureLogAdapter(function ($msg) use(&$message) {
         $message .= $msg . "\n";
     }), LogPlugin::LOG_VERBOSE);
     $client->getEventDispatcher()->addSubscriber($plugin);
     $request = $client->get();
     $multi = new CurlMulti();
     $multi->add($request);
     $multi->send();
     $multi->reset(true);
     $multi->add($request);
     $multi->send();
     $this->assertNotContains('Re-using existing connection', $message);
 }
Beispiel #5
0
 /**
  * Get an existing available CurlMulti handle or create a new one
  *
  * @return CurlMulti
  */
 protected function getAvailableHandle()
 {
     // Grab a handle that is not claimed
     foreach ($this->handles as $h) {
         if (!in_array($h, $this->groups, true)) {
             return $h;
         }
     }
     // All are claimed, so create one
     $handle = new CurlMulti($this->selectTimeout);
     $handle->setEventDispatcher($this->getEventDispatcher());
     $this->handles[] = $handle;
     return $handle;
 }
 /**
  * {@inheritdoc}
  */
 public function getCurlMulti()
 {
     if (!$this->curlMulti) {
         $this->curlMulti = CurlMulti::getInstance();
     }
     return $this->curlMulti;
 }
Beispiel #7
0
 /**
  * @covers Guzzle\Http\Curl\curlMulti::add
  */
 public function testAddsAsyncRequestsNormallyWhenNotSending()
 {
     $multi = new CurlMulti();
     $request = new Request('GET', 'http://www.google.com/');
     $multi->add($request, true);
     // Ensure that the request was added at the correct next scope
     $requests = $this->readAttribute($multi, 'requests');
     $this->assertEquals(array($request), $requests[0]);
 }