@coroutine

@param \Icicle\Socket\Socket $socket
@param \Icicle\Http\Message\Request $request
@param mixed[] $options

@return \Generator

@resolve \Icicle\Http\Message\Response
183529
public function send(Socket $socket, Request $request, array $options = []): \Generator
    {
        $timeout = isset($options['timeout']) ? (float) $options['timeout'] : self::DEFAULT_TIMEOUT;
        $allowPersistent = isset($options['allow_persistent']) ? (bool) $options['allow_persistent'] : true;

        $request = yield from $this->driver->buildRequest($request, $timeout, $allowPersistent);

        yield from $this->driver->writeRequest($socket, $request, $timeout);

        return yield from $this->driver->readResponse($socket, $timeout);
    }
362912
private function accept(SocketServer $server): Generator
    {
        yield from log()->log(
            Log::INFO,
            'NNTP server listening on %s:%d',
            $server->getAddress(),
            $server->getPort()
        );

        while ($server->isOpen()) {
            // Wait for a client to connect.
            $socket = yield from $server->accept();

            // Handle the client in a separate coroutine.
            $coroutine = new Coroutine($this->handleClient($socket));
            $coroutine->done();
        }
    }
519615
public static function send(RequestInterface $request, ClientInterface $client, array $options = [])
    {
        $response = null;
        try {
            $response = $client->send($request, $options);
            $body = $response->getBody()->getContents();
            $data = [];
            if ($body) {
                $response->getBody()->seek(0);
                $body = $response->getBody()->getContents();
                $data = \GuzzleHttp\json_decode($body, true);
            }

            return (array) $data;
        } catch (BadResponseException $e) {
            throw ApiResponseException::create($e->getRequest(), $e->getResponse());
        } catch (\InvalidArgumentException $e) {
            throw ApiResponseException::create($request, $response);
        }
    }
202861
protected function _initRequest($socket, $response)
    {
        $stream = $this->_classes['stream'];

        $curlOptions = $socket->options();
        $curlOptions[CURLOPT_INFILESIZE] = $socket->outgoing()->length();

        if (isset($curlOptions[CURLOPT_FILE])) {
            $response->body(fopen($curlOptions[CURLOPT_FILE], 'w+'));
        }
        $socket->incoming($response->stream());

        if (!$handle = curl_init()) {
            throw new ClientException('Unable to create a new cURL handle');
        }
        curl_setopt_array($handle, $curlOptions);
        return $handle;
    }
410492
public function handle($request, Closure $next, $options = [])
    {
        $response = $next($request);

        if (! $request->isMethodCacheable() || ! $response->getContent()) {
            return $response;
        }

        if (is_string($options)) {
            $options = $this->parseOptions($options);
        }

        if (isset($options['etag']) && $options['etag'] === true) {
            $options['etag'] = md5($response->getContent());
        }

        $response->setCache($options);
        $response->isNotModified($request);

        return $response;
    }
1003624
public static function post($url, $headers = array(), $data = array(), $options = array()) {
		return self::request($url, $headers, $data, self::POST, $options);
	}
64744
public function onRequest($server, $serverSocket, $request, $response)
    {
        $swapHttpRequest = $this->app['request'];

        $httpRequest = $this->createHttpRequest($request);

        $respondent = $this->createRespondent($response);

        $httpRequest->attributes->add([
            'request'    => $request,
            'response'   => $response,
            'respondent' => $respondent
        ]);

        $httpResponse = $this->handleRequest($httpRequest, $respondent);

        $this->sendResponse($respondent, $httpResponse);

        $this->app->instance('request', $swapHttpRequest);
    }
709793
private static function run(Channel $channel, Socket\ClientSocket $socket = null): Promise
    {
        /** @noinspection PhpDeprecationInspection */
        self::$client = new IpcClient(self::callableFromStaticMethod("onReceivedMessage"), $channel, $socket);

        return call(static function () {
            try {
                yield self::$client->run();
            } catch (\Throwable $exception) {
                // Exception rethrown below as part of MultiReasonException.
            }

            list($exceptions) = yield self::terminate();

            if (isset($exception)) {
                $exceptions[] = $exception;
            }

            try {
                yield self::$client->close();
            } catch (\Throwable $exception) {
                $exceptions[] = $exception;
            }

            self::$client = null;

            if (!empty($exceptions)) {
                $exception = new MultiReasonException($exceptions);
                $message = \implode('; ', \array_map(function (\Throwable $exception): string {
                    return $exception->getMessage();
                }, $exceptions));
                throw new ClusterException("Cluster worker failed: " . $message, 0, $exception);
            }
        });
    }
1045179
public function handle(Request $request, $options = []): array
    {
        $this->fillOptions($options);

        try {
            foreach ($this->handlers as $handlerName) {
                /** @var BaseHandler $handler */
                $handler = new $handlerName();
                if (!$handler->handle($request, $this)) {
                    break;
                }
            }
        } catch (\Exception $e) {
            $answer = new \StdClass();
            $answer->jsonrpc = '2.0';
            $answer->error = JsonRpcHandler::handle($e);
            $this->response[] = $answer;
        }

        return \count($this->response) > 1 ? $this->response : (array)$this->response[0];
    }
1342406
public function send($method, $uri, array $options = [])
    {
        $this->calls[] = array('send', $method, $uri, $options);

        return new Response();
    }
886269
public function handle(Exception $exception, ServerRequestInterface $request, ResponseInterface $response, array $options = [])
    {
        $options += $this->defaultOptions;

        if (!$this->checkException($exception, $options['exceptions'])) {
            throw $exception;
        }

        $url = $this->getUrl($request, $options);

        return $response
                ->withHeader('Location', $url)
                ->withStatus($options['statusCode']);
    }
857272
public static function bindTcp(string $ip, int $port, array $options = []) : SocketServer
    {
        return static::bind($ip, $port, \array_merge($options, ['transport' => 'tcp']));
    }
879579
public function execute(Request $request) : Response
    {
        $host = $request->getHost();
        $socket = new ClientSocket($host, 80);
        $socket->connect();
        $communicator = $socket->getCommunicator();
        $communicator->write($request);
        $communicator->writeLine('');$communicator->writeLine('');
        
        $headers = new Headers();
        $body = ''; 
        
        $headerLine = true;

        $statusLine = $communicator->read(1024, PHP_NORMAL_READ);
        while($line = $communicator->read(5000, PHP_NORMAL_READ)){

            if ($headerLine && $line === PHP_EOL) {
                continue;
            }

            if ($headerLine && ($line === "\r" || $line === PHP_EOL)) {
                $headerLine = false;
                continue;
            }

            if ($headerLine) {
                $headers->add(Header::createFromString($line));
            }else{
                $body .= $line;
            }

        }

        return new Response($body, 200, $headers);
    }
150866
public function post($url, $params = array(), $options = array())
    {
        return $this->request($url, self::POST, $params, $options);
    }
1151797
protected function respond($success, $request, $response, $options)
    {
        $success = isset($response['ACK']) && in_array($response['ACK'], ['Success', 'SuccessWithWarning']);

        if (array_key_exists('INVALID', $response) || array_key_exists('VERIFIED', $response)) {
            $response = array_merge($response, $request);
        }

        $response['isRedirect'] = Arr::get($options, 'isRedirect', false);

        return $this->mapResponse($success, $response);
    }
464612
public function render(Request $request, array $options = array())
    {
        $provider = isset($options['provider']) ? $this->getProvider($options['provider']) : $this->getDefaultProvider();
        unset($options['provider']);

        return $provider->render($request, $options);
    }
1145036
public function render(Request $request, array $options = array())
    {
        return $this->doRender(
            $options + array(
                'shortname' => $this->shortName,
                'identifier' => $request->getPathInfo(),
                'count' => $this->count,
            )
        );
    }