Helper method to execute deferred HTTP requests.

@param $request Request|Batch
@throws Exception
@return object of the type of the expected class or array.
347195
public function execute($request)
  {
    if ($request instanceof Request) {
      $request->setUserAgent(
          $this->getApplicationName()
          . " " . self::USER_AGENT_SUFFIX
          . $this->getLibraryVersion()
      );
      if (!$this->getClassConfig("Request", "disable_gzip")) {
        $request->enableGzip();
      }
      $request->maybeMoveParametersToBody();
      return REST::execute($this, $request);
    } else if ($request instanceof Batch) {
      return $request->execute();
    } else {
      throw new Exception("Do not know how to execute this type of object.");
    }
  }
1073865
public function execute($request)
    {

        ArrayObject::ensureArrayObject($request->getModel());
        $this->gateway->execute($status = new GetHttpRequest());

        if (isset($status->request['operation']) === false) {
            $request->markNew();
            return;
        }

        if (isset($status->request['operation']['status'])) {
            $status = $status->request['operation']['status'];

            if (EcommpayBridgeInterface::STATUS_SUCCESS === $status) {
                $request->markCaptured();
                return;
            }

            if (EcommpayBridgeInterface::STATUS_DECLINE === $status) {
                $request->markFailed();
            }
        }
    }
1372099
public static function proxy ($request) {

		if (!$request instanceof Request) {
			$url = $request;

			$request = new Request ();
			$request->setUrl ($url);
			$request->setMethod (Request::METHOD_GET);
		}

		return Client::getInstance ()->process ($request);
	}
529518
public function do_request($request)
    {
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_AUTOREFERER, true);

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_MAXREDIRS, 8);

        $body = $request->body;
        if (is_array($body)) {
            if (isset($headers['Content-Type']) && strpos($request->headers['Content-Type'], 'json') !== false) {
                $body = json_encode($body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            } else {
                $hasFiles = false;
                /** @noinspection ForeachSourceInspection */
                foreach ($body as $k => $v) {
                    if (is_string($v) && strlen($v) > 1 && $v[0] === '@' && $this->filesystem->fileExists($v)) {
                        $hasFiles = true;
                        $file = $this->alias->resolve($v);
                        $body[$k] = curl_file_create($file, mime_content_type($file) ?: null, basename($file));
                    } elseif (is_object($v)) {
                        $hasFiles = true;
                    }
                }

                if (!$hasFiles) {
                    $body = http_build_query($body);
                }
            }
        }

        switch ($request->method) {
            case 'GET':
                break;
            case 'POST':
                curl_setopt($curl, CURLOPT_POST, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
                break;
            case 'PATCH':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
                curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
                break;
            case 'PUT':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
                curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
                break;
            case 'DELETE':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;
            case 'HEAD':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
                curl_setopt($curl, CURLOPT_NOBODY, true);
                break;
            case 'OPTIONS':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'OPTIONS');
                break;
            default:
                throw new NotSupportedException(['`:method` method is not support', 'method' => $request->method]);
                break;
        }

        $timeout = $request->options['timeout'];
        curl_setopt($curl, CURLOPT_URL, $request->url);
        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_HEADER, 1);

        if ($this->_proxy) {
            $parts = parse_url($this->_proxy);
            $scheme = $parts['scheme'];
            if ($scheme === 'http') {
                curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
            } elseif ($scheme === 'sock4') {
                curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
            } elseif ($scheme === 'sock5') {
                curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
            } else {
                throw new NotSupportedException(['`:scheme` scheme of `:proxy` proxy is unknown', 'scheme' => $scheme, 'proxy' => $this->_proxy]);
            }

            curl_setopt($curl, CURLOPT_PROXYPORT, $parts['port']);
            curl_setopt($curl, CURLOPT_PROXY, $parts['host']);
            if (isset($parts['user'], $parts['pass'])) {
                curl_setopt($curl, CURLOPT_PROXYUSERNAME, $parts['user']);
                curl_setopt($curl, CURLOPT_PROXYPASSWORD, $parts['pass']);
            }
        }

        if (isset($request->options['cafile'])) {
            curl_setopt($curl, CURLOPT_CAINFO, $this->alias->resolve($request->options['cafile']));
        }

        if (!$request->options['verify_peer']) {
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        }

        curl_setopt($curl, CURLOPT_HTTPHEADER, $request->headers);

        $start_time = microtime(true);

        $content = curl_exec($curl);

        $err = curl_errno($curl);
        if ($err === 23 || $err === 61) {
            curl_setopt($curl, CURLOPT_ENCODING, 'none');
            $content = curl_exec($curl);
        }

        /** @noinspection NotOptimalIfConditionsInspection */
        if (($errno = curl_errno($curl)) === CURLE_SSL_CACERT && !isset($options['cafile']) && DIRECTORY_SEPARATOR === '\\') {
            $this->logger->warn('ca.pem file is not exists, you should download from https://curl.haxx.se/ca/cacert.pem', 'httpClient.noCaCert');
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

            $content = curl_exec($curl);
            $errno = curl_error($curl);
        }

        $process_time = round(microtime(true) - $start_time, 3);

        if ($errno) {
            throw new ConnectionException(['connect failed: `:url` :message', 'url' => $request->url, 'message' => curl_error($curl)]);
        }

        $header_length = curl_getinfo($curl, CURLINFO_HEADER_SIZE);

        $response = new Response();

        $response->url = $request->url;
        $response->remote_ip = curl_getinfo($curl, CURLINFO_PRIMARY_IP);
        $response->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->headers = explode("\r\n", substr($content, 0, $header_length - 4));
        $response->process_time = $process_time;
        $response->content_type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
        $response->body = substr($content, $header_length);
        $response->stats = [
            'total_time' => curl_getinfo($curl, CURLINFO_TOTAL_TIME),
            'namelookup_time' => curl_getinfo($curl, CURLINFO_NAMELOOKUP_TIME),
            'connect_time' => curl_getinfo($curl, CURLINFO_CONNECT_TIME),
            'pretransfer_time' => curl_getinfo($curl, CURLINFO_PRETRANSFER_TIME),
            'starttransfer_time' => curl_getinfo($curl, CURLINFO_STARTTRANSFER_TIME)];

        curl_close($curl);

        return $response;
    }
178305
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);
        $this->app->make('Illuminate\Contracts\Http\Kernel')->terminate($request, $response);

        return $response;
    }
1341979
protected function handle($request)
    {
        $this->authorize($request, $this->repository()->getClassName());

        $qb = $this->repository()->sourceQueryBuilder($request);
        $this->applyPagination($request, $qb);
        $this->applyFilter($request, $qb);

        return $this->response()->resource($request, $this->prepareCollection($request, $qb));
    }
291419
private function processRequest($request)
    {
        if (!is_array($request)) {
            return self::requestError();
        }

        // The presence of the 'id' key indicates that a response is expected
        $isQuery = array_key_exists('id', $request);

        $id = &$request['id'];

        if (($id !== null) && !is_int($id) && !is_float($id) && !is_string($id)) {
            return self::requestError();
        }

        $version = &$request['jsonrpc'];

        if ($version !== self::VERSION) {
            return self::requestError($id);
        }

        $method = &$request['method'];

        if (!is_string($method)) {
            return self::requestError($id);
        }

        // The 'params' key is optional, but must be non-null when provided
        if (array_key_exists('params', $request)) {
            $arguments = $request['params'];

            if (!is_array($arguments)) {
                return self::requestError($id);
            }
        } else {
            $arguments = array();
        }

        if ($isQuery) {
            return $this->processQuery($id, $method, $arguments);
        }

        $this->processNotification($method, $arguments);
        return null;
    }
447813
private function do_request($curl, $request) {
        $url = $request->getUrl();
        $method = $request->getRequestMethod();
        switch (strtoupper($method)) {
            case 'POST':
                $ret = $curl->post($url, $request->getPostBody());
                break;
            case 'GET':
                $ret = $curl->get($url);
                break;
            case 'HEAD':
                $ret = $curl->head($url);
                break;
            case 'PUT':
                $ret = $curl->put($url);
                break;
            default:
                throw new coding_exception('Unknown request type: ' . $method);
                break;
        }
        return $ret;
    }
614616
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        if (null === $model['error_code']) {
            $request->markNew();
            return;
        }

        if (self::SUCCESS === $model['error_code']) {
            $request->markCaptured();
            return;
        }

        $request->markFailed();

    }
312250
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);


        $details = ArrayObject::ensureArrayObject($request->getModel());

        /** if no payment type provided in config, execute a choose payment type action
         so that user can choose the payment type*/
        if ($details[PayBoxRequestParams::PBX_TYPEPAIEMENT] == null
            && $this->api->getOptions()['type_paiement'] == null) {
            $choosePaymentTypeRequest = new ChoosePaymentType($details);
            $this->gateway->execute($choosePaymentTypeRequest);
        }

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

        if (isset($httpRequest->query['error_code'])) {
            $details->replace($httpRequest->query);
        } else {
            $this->api->doPayment((array)$details);
        }
    }
449989
public function handleRequest(Request $request): Promise {
        $method = $request->getMethod();
        $path = \rawurldecode($request->getUri()->getPath());

        $toMatch = "{$method}\0{$path}";

        if (null === $match = $this->cache->get($toMatch)) {
            $match = $this->routeDispatcher->dispatch($method, $path);
            $this->cache->put($toMatch, $match);
        }

        switch ($match[0]) {
            case Dispatcher::FOUND:
                /**
                 * @var RequestHandler $requestHandler
                 * @var string[] $routeArgs
                 */
                list(, $requestHandler, $routeArgs) = $match;
                $request->setAttribute(self::class, $routeArgs);

                return $requestHandler->handleRequest($request);

            case Dispatcher::NOT_FOUND:
                if ($this->fallback !== null) {
                    return $this->fallback->handleRequest($request);
                }

                return $this->makeNotFoundResponse($request);

            case Dispatcher::METHOD_NOT_ALLOWED:
                return $this->makeMethodNotAllowedResponse($match[1], $request);

            default:
                // @codeCoverageIgnoreStart
                throw new \UnexpectedValueException(
                    "Encountered unexpected dispatcher code: " . $match[0]
                );
                // @codeCoverageIgnoreEnd
        }
    }
594990
protected function processRequest(array $request)
    {
        try {
            $response = $this->_request(
                [
                    'uri' => $request['uri'],
                    'type' => $request['type'],
                    'data' => $request['data']
                ]
            );
        } catch ( \Exception $e ) {
            echo json_encode(array(
                'error' => array(
                    'msg' => $e->getMessage(),
                    'code' => $e->getCode(),
                ),
            ));

            exit();
        }

        return $response->getBody()->getContents();
    }
251842
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        $this->gateway->execute($status = new GetHumanStatus($model));
        if ($status->isCaptured()) {
            $model['state_override'] = 'refunded';
        }
    }
1201574
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $details = ArrayObject::ensureArrayObject($request->getModel());

        if (isset($details['RtnCode']) === false) {
            $request->markNew();

            return;
        }

        if ($details['RtnCode'] === '2') {
            $request->markPending();

            return;
        }

        if ($details['RtnCode'] === '1') {
            if (isset($details['Action']) === true) {
                switch ($details['Action']) {
                    case 'C':
                        $request->markCaptured();
                        break;
                    case 'R':
                        $request->markRefunded();
                        break;
                    case 'E':
                    case 'N':
                        $request->markCanceled();
                        break;
                }

                return;
            } else {
                $request->markCaptured();

                return;
            }
        }

        $request->markFailed();
    }
1213968
public function executeRequest(Request $request)
    {
        $curl = curl_init();

        if ($request->getPostBody()) {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody());
        }

        $requestHeaders = $request->getRequestHeaders();
        if ($requestHeaders && is_array($requestHeaders)) {
            $curlHeaders = array();
            foreach ($requestHeaders as $k => $v) {
                $curlHeaders[] = "$k: $v";
            }
            curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders);
        }
        curl_setopt($curl, CURLOPT_URL, $request->getUrl());

        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod());
        curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent());

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
        // 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP.
        curl_setopt($curl, CURLOPT_SSLVERSION, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, true);

        if ($request->canGzip()) {
            curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
        }

        $options = $this->client->getClassConfig('Goracash\IO\Curl', 'options');
        if (is_array($options)) {
            $this->setOptions($options);
        }

        foreach ($this->options as $key => $var) {
            curl_setopt($curl, $key, $var);
        }

        $this->client->getLogger()->debug(
            'cURL request',
            array(
                'url' => $request->getUrl(),
                'method' => $request->getRequestMethod(),
                'headers' => $requestHeaders,
                'body' => $request->getPostBody()
            )
        );

        $result = curl_exec($curl);
        if ($result === false) {
            $error = curl_error($curl);
            $code = curl_errno($curl);
            $this->client->getLogger()->error('cURL ' . $error);
            throw new Exception($error, $code);
        }

        $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        list($responseHeaders, $responseBody) = $this->parseHttpResponse($result, $headerSize);

        $response = new Response();
        $response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->url = $request->getUrl();
        $response->method = $request->getRequestMethod();
        $response->headers = $responseHeaders;
        $response->body = $responseBody;
        $response->status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->setContentType(curl_getinfo($curl, CURLINFO_CONTENT_TYPE));

        $this->client->getLogger()->debug(
            'cURL response',
            array(
                'code' => $response->code,
                'headers' => $response->headers,
                'body' => $response->body,
            )
        );
        return $response;
    }
229660
public function makeRequest($request)
    {
        $optionsSet = curl_setopt_array($this->ch, [
            CURLOPT_URL => $this->url,
            CURLOPT_HEADER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CONNECTTIMEOUT => $this->timeout,
            CURLOPT_USERAGENT => 'JSON-RPC Random.org PHP Client',
            CURLOPT_HTTPHEADER => $this->headers,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_SSL_VERIFYPEER => $this->verifyPeer,
            CURLOPT_POSTFIELDS => json_encode($request)
        ]);

        if (!$optionsSet) {
            throw new \Exception('Cannot set curl options');
        }

        $responseBody = curl_exec($this->ch);
        $responseCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

        if (curl_errno($this->ch)) {
            throw new \RuntimeException(curl_error($this->ch));
        }

        if ($responseCode === 401 || $responseCode === 403) {
            throw new \RuntimeException('Access denied');
        }

        $response = json_decode($responseBody, true);

        if ($this->debug) {
            echo('==> Request: '.PHP_EOL.json_encode($request, JSON_PRETTY_PRINT));
            echo('==> Response: '.PHP_EOL.json_encode($response, JSON_PRETTY_PRINT));
        }

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

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

        if ($this->api->verifyHash($httpRequest->request) === false) {
            throw new HttpResponse('0|CheckMacValue verify fail.', 400, ['Content-Type' => 'text/plain']);
        }

        $details->replace($httpRequest->request);

        throw new HttpResponse('1|OK', 200, ['Content-Type' => 'text/plain']);
    }