Adds a request to the batch execution queue
@param ClientRequestInterface $request
@return $this
974126
public function addBatchRequest(ClientRequestInterface $request)
    {
        if ($request instanceof ContextAwareInterface) {
            $request->setContextIfNull($this->getConfig()->getContext());
        }
        $this->batchRequests[] = $request;
        return $this;
    }
178066
public function dispatch(ServerRequestInterface $request)
    {
        parse_str($request->getUri()->getQuery(), $args);
        $uri = '/';
        if (isset($args['page'])) {
            $uri .= $args['page'];
        }

        return $this->createDispatcher()->dispatch(
            $request->getMethod(),
            $uri
        );
    }
1190909
public function execute(RequestInterface $request): RequestInterface
    {
        $body = $request->getBody()->getContents();

        $iv = random_bytes(self::INITIATION_VECTOR_LENGTH);
        $aesKey = random_bytes(self::AES_KEY_LENGTH);
        $encryptedAesKey = $this->publicKey->encrypt($aesKey);
        $bodyEncrypted = $this->determineBodyStringEncrypted($body, $aesKey, $iv);
        $hmac = $this->determineHmac($aesKey, $iv, $bodyEncrypted);
        $encryptedHeaders = [
            self::HEADER_CLIENT_ENCRYPTION_IV => [base64_encode($iv)],
            self::HEADER_CLIENT_ENCRYPTION_KEY => [base64_encode($encryptedAesKey)],
            self::HEADER_CLIENT_ENCRYPTION_HMAC => [base64_encode($hmac)],
        ];

        return new Request(
            $request->getMethod(),
            $request->getUri(),
            array_merge($request->getHeaders(), $encryptedHeaders),
            $bodyEncrypted
        );
    }
52969
public function setRequest(Request $request)
    {
        $this->request = $request;
        $this->getContainer()->register('request', $request);
        return $this;
    }
961204
private function decorateRequest(ServerRequestInterface $request)
    {
        if ($request instanceof Http\Request) {
            return $request;
        }

        return new Http\Request($this, $request);
    }
88832
protected function makeExecuteRequest(Collection $requests)
    {
        $clientRequests = $requests->map(function (VkRequest $request) {
            return new Request($request->method, $request->parameters);
        });

        return ExecuteRequest::make($clientRequests->all());
    }
1279326
private function createRequestManager(ServerRequestInterface $request)
    {
        return new Promise(function ($resolve, $reject) use ($request) {
            $bodyStream = '';

            $request->getBody()->on('data', function ($data) use (&$bodyStream, $request) {
                $bodyStream .= $data;
            });
            $request->getBody()->on('end', function () use ($resolve, $request, &$bodyStream) {
                $response = $this->onRequest($request->withBody(new StringStream($bodyStream)));
                $resolve($response);
            });
            $request->getBody()->on('error', function (\Exception $exception) use ($resolve) {
                $response = new ReactResponse(
                    400,
                    ['Content-Type' => 'text/plain'],
                    'An error occured while reading: ' . $exception->getMessage()
                );
                $resolve($response);
            });
        });
    }
1070753
public function setRequest(\WowApi\Request\RequestInterface $request)
    {
        $request->setClient($this);
        $this->request = $request;
    }
680749
public function sendRequest(RequestInterface $request): ResponseInterface
    {
        $promise = $this->sendAsyncRequest($request);

        return $promise->wait();
    }
1361285
public function dequeue(RequestInterface $request)
    {
        $this->dispatch('mock.request', array('plugin' => $this, 'request' => $request));

        $item = array_shift($this->queue);
        if ($item instanceof Response) {
            if ($this->readBodies && $request instanceof EntityEnclosingRequestInterface) {
                $request->getEventDispatcher()->addListener('request.sent', $f = function (Event $event) use (&$f) {
                    while ($data = $event['request']->getBody()->read(8096));
                    // Remove the listener after one-time use
                    $event['request']->getEventDispatcher()->removeListener('request.sent', $f);
                });
            }
            $request->setResponse($item);
        } elseif ($item instanceof CurlException) {
            // Emulates exceptions encountered while transferring requests
            $item->setRequest($request);
            $state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $item));
            // Only throw if the exception wasn't handled
            if ($state == RequestInterface::STATE_ERROR) {
                throw $item;
            }
        }

        return $this;
    }
764744
protected function executeRequest(Request $request)
    {
        $index = array_search($request, $this->waitingRequests);
        if ($index !== false) {
            unset($this->waitingRequests[$index]);
            $this->hydrateCurlFromRequest($request, $request->getCurl())
                 ->triggerCallback($request->getOnInitializeCallback(), $request);

            $this->multiCurl->addCurl($request->getCurl());
            $this->runningRequests[] = $request;
            $this->executeMultiCurl();
        }
        return $this;
    }
1162437
public function sendRequest(RequestInterface $request)
    {
        if (isset($this->promises[$request->getRequestId()])) {
            return promise\reject(new ClientException("ID {$request->getRequestId()} already in use"));
        }
        $this->responseBuilders[$request->getRequestId()] = new ResponseParser($request->getRequestId());
        $this->promises[$request->getRequestId()] = new Deferred();
        foreach ($request->toRecords() as $record) {
            $this->connector->write($record->encode());
        }

        return $this->promises[$request->getRequestId()]->promise();
    }
878036
protected function executeNextWaitingRequest()
    {
        if (($this->numberOfParallelRequests === 0 || count($this->runningRequests) < $this->numberOfParallelRequests)
            && count($this->waitingRequests) > 0
        ) {
            $this->executeRequest(reset($this->waitingRequests));
        }
        return $this;
    }
1113074
public function handleRequest(ServerRequestInterface $request)
    {
        $requestBody = (array) $request->getParsedBody();

        // Set debug mode
        $this->debugMode = isset($requestBody['custom_debug']) && (strtolower($requestBody['custom_debug']) == 'true');

        // Set return URL if available
        if (isset($requestBody['launch_presentation_return_url'])) {
            $this->returnUrl = $requestBody['launch_presentation_return_url'];
        } else if (isset($requestBody['content_item_return_url'])) {
            $this->returnUrl = $requestBody['content_item_return_url'];
        }

        // Perform action
        if ($this->authenticate($request)) {
            $this->doCallback($requestBody);
        }

        $this->result();
    }
669300
public function doRequest(HttpRequestInterface $request)
    {
        $responseClass = $this->responseClass;

        /** @var HttpResponseInterface $responseObject */
        $responseObject = new $responseClass();

        return $responseObject->build($request);
    }
1085157
public function execute(ClientRequestInterface $request, array $headers = null, array $clientOptions = [])
    {
        if ($request instanceof ContextAwareInterface) {
            $request->setContextIfNull($this->getConfig()->getContext());
        }
        $httpRequest = $this->createHttpRequest($request, $headers);

        try {
            $client = $this->getHttpClient();
            if ($client instanceof AdapterOptionInterface) {
                $httpResponse = $client->execute($httpRequest, $clientOptions);
            } else {
                $httpResponse = $client->execute($httpRequest);
            }
            $response = $request->buildResponse($httpResponse);
        } catch (ApiException $exception) {
            if ($exception instanceof InvalidTokenException && !$this->tokenRefreshed) {
                $this->tokenRefreshed = true;
                $this->getOauthManager()->refreshToken();
                return $this->execute($request);
            }
            if ($this->getConfig()->getThrowExceptions() || !$exception->getResponse() instanceof ResponseInterface) {
                throw $exception;
            }
            $httpResponse = $exception->getResponse();
            $this->logException($exception);
            $response = new ErrorResponse($exception, $request, $httpResponse);
        }
        $this->logDeprecatedRequest($httpResponse, $httpRequest);


        return $response;
    }
132083
public function handleRequest(ServerRequestInterface $request) : ResponseInterface
    {
        list($callback, $params) = $this->internalRequestHandle($request);

        return call_user_func($callback, $params);
    }