Execute an outbound HTTP/1.1 request to nghttpx

@param ClientRequest $clientRequest
@return ClientResponse
@throws Error
@throws \Google\Protobuf\Internal\Exception
@throws \Grphp\Protobuf\SerializationException
485179
public function execute(ClientRequest $clientRequest): ClientResponse
    {
        $response = null;
        $request = $this->requestFactory->build($clientRequest);
        try {
            $response = $this->requestExecutor->send($request);
        } catch (RequestException $e) {
            $status = new Error\Status(Error\Status::CODE_INTERNAL, $e->getErrorMessage(), $e->getHeaders());
            $clientRequest->fail($status);
        }

        return $this->handleSuccess($clientRequest, $response);
    }
1026462
protected function sendRequest(Request $request)
    {
        // Try to get the result.  Handle the possible exceptions that can arise
        try {
            $response = $this->client->send($request);

            $result       = new stdClass();
            $result->code = $response->getStatusCode();
            $result->body = json_decode($response->getBody(true));
        } catch (ClientErrorResponseException $e) {
            throw new ApiCallFailedException($e->getMessage(), $e->getResponse()->getStatusCode(), $e);
        } catch (ServerErrorResponseException $e) {
            throw new ApiCallFailedException('Api call failed to complete due to a server error.', $e->getResponse()->getStatusCode(), $e);
        } catch (Exception $e) {
            throw new ApiCallFailedException($e->getMessage(), $e->getCode(), $e);
        }

        // If all worked out, return the result
        return $result;
    }
216793
public function handleRequest(IHttpClient $request)
    {
        foreach ($this->_headers as $key => $value) {
            $headers = $request->getHeaders();
            if (!array_key_exists($key, $headers)) {
                $request->setHeader($key, $value);
            }
        }

        return $request;
    }
1199642
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);
        $details = ArrayObject::ensureArrayObject($request->getModel());

        $httpRequest = new GetHttpRequest();
        $this->gateway->execute($httpRequest);

        if (isset($httpRequest->request['RtnCode']) === true) {
            if ($this->api->verifyHash($httpRequest->request) === false) {
                $httpRequest->request['RtnCode'] = '10400002';
            }
            $details->replace($httpRequest->request);

            return;
        }

        $token = $request->getToken();
        $targetUrl = $token->getTargetUrl();

        if (empty($details['OrderResultURL']) === true) {
            $details['OrderResultURL'] = $targetUrl;
        }

        if (empty($details['ReturnURL']) === true) {
            $notifyToken = $this->tokenFactory->createNotifyToken(
                $token->getGatewayName(), $token->getDetails()
            );
            $details['ReturnURL'] = $notifyToken->getTargetUrl();
        }
        $this->gateway->execute(new CreateTransaction($details));
    }
1279098
public function sendRequest(Request $request)
    {
        $response = $this->httpClient->send($request);

        $this->checkErrorResponse($response);

        return $response;
    }
35253
public function call(string $method, RequestInterface $request)
    {
        try {
            $parameters = $request->toArray();

            return $this->__soapCall($method, ['parameters' => $parameters]);
        } catch (\Exception $exception) {
            if ($this->debug) {
                throw ClientException::create($this, $exception);
            }

            throw new ClientException($exception->getMessage(), $exception->getCode(), $exception);
        }
    }
945854
public function process($serverRequest)
    {
        $match = $this->routeTranslator->match($serverRequest);
        
        if($match !== null) {
            $attributes = $match->attributes();
            $attributes['routeResolverPath'] = $match->resolverPath();

            foreach($attributes as $key => $value) {
                $serverRequest = $serverRequest->withAttribute($key, $value);
            }
        }
        
        return $serverRequest;
    }
1210386
protected function clientFetch(Client $client, FetchRequest $msg)
    {
        $requestId     = $msg->getRequestId();
        $waitForResult = $msg->getWaitForResult();

        $client->setRequest($requestId, $waitForResult);

        $this->getLogger()->debug(
            sprintf(
                'Client %s is requesting the result of request %s.',
                bin2hex($client->getId()),
                $requestId
            )
        );

        if ($this->storage->has($requestId)) {
            $this->sendResponseToClients($requestId);

            return;
        }

        $this->logger->debug(
            sprintf(
                'The result for request %s is not yet available, but '.
                'client %s is %s to wait for it.',
                $requestId,
                bin2hex($client->getId()),
                ($waitForResult) ? 'willing' : 'not willing'
            )
        );

        if (!$waitForResult) {
            $this->reply($client, new TimeoutResponse($requestId));;
        }
    }
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);
    }
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);
        }
    }
1140628
public function clientRequest(Client $client, ExecuteRequest $msg)
    {
        $requestId = $msg->getRequestId();
        if (!$requestId) {
            // No requestId given, generate a unique one.
            do {
                $requestId = sha1(uniqid());
            } while (isset($this->request[$requestId]));
        }

        if ($this->storage->has($requestId)) {
            $this->getLogger()->info(
                sprintf(
                    'Client %s wants to execute request %s. '.
                    'Since there already is a result for that request, '.
                    'it will be sent back immediately.',
                    bin2hex($client->getId()),
                    $requestId
                )
            );

            $this->reply(
                $client,
                new ExecuteResponse(
                    $requestId,
                    $this->storage->get($requestId)
                )
            );

            return;
        }

        // The Client always needs to receive this
        // response, so just send it right away.
        $this->reply($client, new ExecuteResponse($requestId));

        // Now actually handle the message.
        $request = $this->getRequest($requestId);

        if ($request) {
            $this->getLogger()->info(
                sprintf(
                    'Client %s wants to execute already known request %s.',
                    bin2hex($client->getId()),
                    $requestId
                )
            );

            return;
        }

        $action = $msg->getAction();
        $params = $msg->getParams();

        $this->getLogger()->info(
            sprintf(
                'New request %s from client %s for action %s',
                $requestId,
                bin2hex($client->getId()),
                $action
            )
        );

        $this->addRequest(new Request($requestId, $action, $params));

        if (!$this->storage->has($requestId)) {
            $this->addWorkerQueue($requestId);
        }
    }
508968
public function execute(RequestInterface $request): ResponseInterface
    {
        $this->supports($request);

        if ($request instanceof InputInterface) {
            $request->validate();
        }

        $client = $this->getClient();

        $data = array_replace($request->toArray(), [
            'carrier' => $client->getCarrier(),
            'key'     => $client->getKey(),
        ]);

        $response = $client->call($this->getMethodName(), $data);

        return $this->parseResponse($response->getBody()->getContents());
    }
432368
public function sendMessage(SendMessageRequest $request)
    {
        $response = new SendMessageResponse();
        return $this->client->sendRequest($request, $response);
    }
66286
protected function determineException(ClientException $exception): Exception
    {
        if (in_array($exception->getResponse()->getStatusCode(), [400, 403, 404, 409])) {
            return new BadRequest($exception->getResponse());
        }

        return $exception;
    }
223650
protected function doRequest($request)
    {
        if (!$this->firstRequest) {
            $this->initialize($request);
        }
        $this->firstRequest = false;

        $this->applyBindings();
        $this->applyContextualBindings();
        $this->applyInstances();
        $this->applyApplicationHandlers();

        $request = Request::createFromBase($request);
        $response = $this->kernel->handle($request);

        $method = new \ReflectionMethod(get_class($this->app), 'callTerminableMiddleware');
        $method->setAccessible(true);
        $method->invoke($this->app, $response);

        return $response;
    }
809071
public function execute($request)
    {
        ob_start();
        $logger          = $GLOBALS['logger'];
        $this->_request  = $request;
        $this->_response = new HttpResponse();
        try {
            WebSessionManager::updateActiveSession();
            foreach ($this->_preProcessors as $preProcessor) {
                $preProcessor->process($this->_request);
            }

            $functionToCall = $this->command->getFunction();
            if (empty($functionToCall) === true) {
                $functionToCall = 'default';
            }

            if (!is_callable(array(&$this,'_'.$functionToCall))) {
                $functionToCall = 'error';
            }

            call_user_func(array(&$this,'_'.$functionToCall), $this->_request);
            foreach ($this->_postProcessors as $postProcessor) {
                $postProcessor->process($this->_response);
            }

            ob_end_clean();
            if (empty($this->_response)) {
                $this->_response = new HttpResponse(); 
            }

            if($this->_response->getEncoding() == null) {
                $responseMode = $this->_request->getParam('mode');
                if ($responseMode === 'ui') {
                    $this->_response->setEncoding('html');
                } else if ($responseMode === 'data') {
                    $this->_response->setEncoding('json');
                }
            }
            $this->_response->send();
        } catch (ServiceException $se) {
            $this->_response = new HttpResponse();
            $response->addHeader('HTTP/1.1 400 Bad Request');
            $this->_response->send();
        } catch(BadResponseException $bre) {
            $renderer = new TwigRenderer('500.html');
            if($renderer->exists()) {
                $this->_response = new HttpResponse('none', $renderer);
            } else 
                $this->_response = new HttpResponse();
            $response->addHeader('HTTP/1.1 500 Internal Server Error');
            $this->_response->send();
        }//end try

    }
3784
public function request($serverRequest = null)
    {
        if ($serverRequest === null) {
            $serverRequest = $this->sapiServerRequest();
        }
        return $this->builder->request($serverRequest);
    }