Ejemplo n.º 1
0
 public function __construct(LoopInterface $loop, Sender $sender = null, MessageFactory $messageFactory = null)
 {
     if ($sender === null) {
         $sender = Sender::createFromLoop($loop);
     }
     if ($messageFactory === null) {
         $messageFactory = new MessageFactory();
     }
     $this->sender = $sender;
     $this->loop = $loop;
     $this->messageFactory = $messageFactory;
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider provideRequestProtocolVersion
  */
 public function testRequestProtocolVersion(Request $Request, $method, $uri, $headers, $protocolVersion)
 {
     $httpClientArguments = array();
     $ref = new \ReflectionClass('React\\HttpClient\\Client');
     if ($ref->getConstructor()->getNumberOfRequiredParameters() == 3) {
         $httpClientArguments[] = $this->getMock('React\\EventLoop\\LoopInterface');
     }
     $httpClientArguments[] = $this->getMock('React\\SocketClient\\ConnectorInterface');
     $httpClientArguments[] = $this->getMock('React\\SocketClient\\ConnectorInterface');
     $http = $this->getMock('React\\HttpClient\\Client', array('request'), $httpClientArguments);
     $requestArguments = array();
     $ref = new \ReflectionClass('React\\HttpClient\\Request');
     if ($ref->getConstructor()->getNumberOfRequiredParameters() == 3) {
         $requestArguments[] = $this->getMock('React\\EventLoop\\LoopInterface');
     }
     $requestArguments[] = $this->getMock('React\\SocketClient\\ConnectorInterface');
     $requestArguments[] = new RequestData($method, $uri, $headers, $protocolVersion);
     $request = $this->getMock('React\\HttpClient\\Request', array(), $requestArguments);
     $http->expects($this->once())->method('request')->with($method, $uri, $headers, $protocolVersion)->willReturn($request);
     $sender = new Sender($http);
     $sender->send($Request, $this->getMock('Clue\\React\\Buzz\\Message\\MessageFactory'));
 }
Ejemplo n.º 3
0
 /**
  * Creates a new Client instance and helps with constructing the right Browser object for the given remote URL
  *
  * @param null|string $url (optional) URL to your (local) Docker daemon, defaults to using local unix domain socket path
  * @return Client
  */
 public function createClient($url = null)
 {
     if ($url === null) {
         $url = 'unix:///var/run/docker.sock';
     }
     $browser = $this->browser;
     if (substr($url, 0, 7) === 'unix://') {
         // send everything through a local unix domain socket
         $browser = $this->browser->withSender(Sender::createFromLoopUnix($this->loop, $url));
         // pretend all HTTP URLs to be on localhost
         $url = 'http://localhost/';
     }
     return new Client($browser->withBase($url));
 }
Ejemplo n.º 4
0
 public function testVerifyPeerDisabledForBadSslResolves()
 {
     if (!function_exists('stream_socket_enable_crypto')) {
         $this->markTestSkipped('Not supported on your platform (outdated HHVM?)');
     }
     if (!class_exists('React\\SocketClient\\TcpConnector')) {
         $this->markTestSkipped('Test requires SocketClient:0.5');
     }
     $dnsResolverFactory = new DnsFactory();
     $resolver = $dnsResolverFactory->createCached('8.8.8.8', $this->loop);
     $tcp = new DnsConnector(new TcpConnector($this->loop), $resolver);
     $ssl = new SecureConnector($tcp, $this->loop, array('verify_peer' => false));
     $sender = Sender::createFromLoopConnectors($this->loop, $tcp, $ssl);
     $browser = $this->browser->withSender($sender);
     Block\await($browser->get('https://self-signed.badssl.com/'), $this->loop);
 }
Ejemplo n.º 5
0
<?php

use Clue\React\Buzz\Io\Sender;
use React\SocketClient\TcpConnector;
use React\EventLoop\Factory as LoopFactory;
use Clue\React\Socks\Client as SocksClient;
use Clue\React\Buzz\Browser;
use Psr\Http\Message\ResponseInterface;
use RingCentral\Psr7;
require __DIR__ . '/vendor/autoload.php';
$loop = LoopFactory::create();
// create a new SOCKS client which connects to a SOCKS server listening on localhost:9050
// not already running a SOCKS server? Try this: ssh -D 9050 localhost
$socks = new SocksClient('127.0.0.1:9050', new TcpConnector($loop));
// create a Browser object that uses the SOCKS client for connections
$sender = Sender::createFromLoopConnectors($loop, $socks);
$browser = new Browser($loop, $sender);
// demo fetching HTTP headers (or bail out otherwise)
$browser->get('https://www.google.com/')->then(function (ResponseInterface $response) {
    echo Psr7\str($response);
}, 'printf');
$loop->run();