Beispiel #1
0
 /**
  * Coroutine that performs the WebSocket handshake and upgrades the socket connection to a WebSocket in client mode.
  */
 protected function handshake(string $uri, array $protocols) : \Generator
 {
     $location = $uri;
     $m = null;
     if (\preg_match("'^(wss?)://.+\$'i", $uri, $m)) {
         $uri = (\strtolower($m[1]) === 'ws' ? 'http' : 'https') . \substr($m[0], \strlen($m[1]));
     }
     $nonce = \base64_encode(\random_bytes(16));
     $request = $this->createHandshakeRequest($uri, $nonce, $protocols);
     $response = (yield $this->httpClient->send($request));
     $this->assertHandshakeSucceeded($response, $nonce, $protocols);
     // Discard HTTP body contents but do not close the underlying socket stream.
     $stream = (yield $response->getBody()->getReadableStream());
     while (null !== (yield $stream->read())) {
     }
     return $this->establishConnection($location, $response);
 }
Beispiel #2
0
 public function __construct(array $connectors, HttpTestEndpoint $server)
 {
     parent::__construct(...$connectors);
     $this->server = $server;
     $this->workers = new \SplObjectStorage();
 }
Beispiel #3
0
 public function __construct(array $responses)
 {
     parent::__construct();
     $this->responses = $responses;
 }