Adds request id to request and return new instance

@param RequestInterface $request

@return RequestInterface
325303
public function decorate(RequestInterface $request)
    {
        return $request->withHeader($this->headerName, $this->requestIdProvider->getRequestId());
    }
1100008
public function onRequest( RequestInterface $request ) {
        $apiKey = $this->getEndpoint()->getApiKey();

        if($apiKey !== null) {
            $request = $request->withHeader( 'Authorization', 'Bearer '.$apiKey);
        }

        return $request;
    }
199357
public function getResponse(RequestInterface $request)
    {
        $response = $this->sendRequest($request);
        $parsed = $this->parseResponse($response);

        $this->checkResponse($response, $parsed);

        return $parsed;
    }
1158094
public static function setRequest(RequestInterface $request)
    {
        $fd = self::getFdByCoId();

        self::$connections[$fd][self::REQUEST_KEY] = $request;
    }
107307
protected function getOriginalRequest(RequestInterface $request)
    {
        $original = $request;
        // The number of redirects is held on the original request, so determine which request that is
        while ($parent = $original->getParams()->get(self::PARENT_REQUEST)) {
            $original = $parent;
        }

        return $original;
    }
226125
public function send(RequestInterface $request)
    {
        /** @var RequestEvent $event */
        $event = new RequestEvent($request);
        $event = $this->eventDispatcher->dispatch(ClientEvents::REQUEST, $event);

        $request = $event->getRequest();

        $response = $this->httpClient->send($request);

        /** @var ResponseEvent $event */
        $event = new ResponseEvent($response);
        $event = $this->eventDispatcher->dispatch(ClientEvents::RESPONSE, $event);

        return $event->getResponse();
    }
1359719
public function getRequest(): RequestInterface
    {
        if (!$this->request) {
            $this->resolveOptions();
            $this->request = $this->createRequest();
        }

        return parent::getRequest();
    }
461882
public function createHandle(RequestInterface $request)
    {
        // Setup the cURL handle.
        $ch = curl_init();

        // Set the request method.
        $options[CURLOPT_CUSTOMREQUEST] = $request->getMethod();

        // Don't wait for body when $method is HEAD
        $options[CURLOPT_NOBODY] = ($request->getMethod() === 'HEAD');

        // Initialize the certificate store
        $options = $this->setCABundleToOptions($options);

        // Set HTTP Version
        switch ($request->getProtocolVersion()) {
            case '1.0':
                $options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
                break;

            case '1.1':
                $options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
                break;

            case '2':
                if (defined('CURL_HTTP_VERSION_2_0')) {
                    $options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0;
                }
        }

        // If data exists let's encode it and make sure our Content-type header is set.
        $data = (string) $request->getBody();

        if (isset($data)) {
            // If the data is a scalar value simply add it to the cURL post fields.
            if (is_scalar($data) || strpos($request->getHeaderLine('Content-Type'), 'multipart/form-data') === 0) {
                $options[CURLOPT_POSTFIELDS] = $data;
            } else // Otherwise we need to encode the value first.
            {
                $options[CURLOPT_POSTFIELDS] = http_build_query($data);
            }

            if (!$request->getHeaderLine('Content-Type')) {
                $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
            }

            // Add the relevant headers.
            if (is_scalar($options[CURLOPT_POSTFIELDS])) {
                $request = $request->withHeader('Content-Length', (string) strlen($options[CURLOPT_POSTFIELDS]));
            }
        }

        // Build the headers string for the request.
        if ($headers = $request->getHeaders()) {
            // Add the headers string into the stream context options array.
            $options[CURLOPT_HTTPHEADER] = HeaderHelper::toHeaderLine($headers);
        }

        // If an explicit timeout is given user it.
        if ($timeout = $this->getOption('timeout')) {
            $options[CURLOPT_TIMEOUT] = (int) $timeout;
            $options[CURLOPT_CONNECTTIMEOUT] = (int) $timeout;
        }

        // If an explicit user agent is given use it.
        if ($userAgent = $this->getOption('userAgent')) {
            $options[CURLOPT_USERAGENT] = $userAgent;
        }

        // Set the request URL.
        $options[CURLOPT_URL] = (string) $request->getRequestTarget();

        // We want our headers. :-)
        $options[CURLOPT_HEADER] = true;

        // Return it... echoing it would be tacky.
        $options[CURLOPT_RETURNTRANSFER] = true;

        // Override the Expect header to prevent cURL from confusing itself in its own stupidity.
        // Link: http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/
        $options[CURLOPT_HTTPHEADER][] = 'Expect:';

        /*
         * Follow redirects if server config allows
         */
        if (!ini_get('open_basedir')) {
            $options[CURLOPT_FOLLOWLOCATION] = (bool) isset($this->options['follow_location'])
                ? $this->options['follow_location']
                : true;
        }

        // Set any custom transport options
        if ($this->getOption('options')) {
            foreach ((array) $this->getOption('options') as $key => $value) {
                $options[$key] = $value;
            }
        }

        // Set the cURL options.
        curl_setopt_array($ch, $options);

        return $ch;
    }
588148
public function sendAsyncRequest(RequestInterface $request)
    {
        try {
            return new Promise\HttpFulfilledPromise($this->sendRequest($request));
        } catch (Exception $e) {
            return new Promise\HttpRejectedPromise($e);
        }
    }
656618
public function getResponseFor(RequestInterface $request): ResponseInterface
    {
        try {
            return $this->responses[$request];
        } catch (\UnexpectedValueException $e) {
            throw new \UnexpectedValueException('Request not found', $e->getCode(), $e);
        }
    }
259623
public function handle(RequestInterface $request): RequestInterface
    {
        return
            $request->withHeader(
                'Authorization',
                sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->user, $this->password)))
            );
    }
490124
public function modify(RequestInterface $request) : RequestInterface
    {
        /** @var RequestModifierInterface $modifier */
        foreach ($this->collection as $modifier) {
            $request = $modifier->modify($request);
        }

        return $request;
    }
178476
public function sendRequest(RequestInterface $request)
    {
        if (false === is_resource($this->resource)) {
            $this->resource = curl_init();
        }

        $response = $this->channelBuilder
            ->channel($this->resource)
            ->options(array_replace($this->options, $this->requestOptions))
            ->request($request)
            ->response($this->responseFactory->createResponse())
            ->getChannel()
            ->send();

        $response->getBody()->rewind();
        $this->requestOptions = [];

        return $response;
    }
1302191
protected function createUrl(RequestInterface $request)
    {
        $query = $request->buildQuery();

        if ($this->hasKey()) {
            $query['key'] = $this->key;
        }

        $url = $this->createBaseUrl($request).'?'.http_build_query($query, '', '&');

        if ($this->hasBusinessAccount()) {
            $url = $this->businessAccount->signUrl($url);
        }

        return $url;
    }
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
        );
    }
33878
protected function setAllowance(RequestInterface $request)
    {
        return function (ResponseInterface $response) use ($request) {
            $this->provider->setRequestAllowance($request, $response);

            return $response;
        };
    }
586046
private function appendQueryParams(RequestInterface $request)
    {
        $queryParams = $this->auth->getQueryParameters();
        foreach ($queryParams as $key => $value) {
            $uri = Uri::withQueryValue($request->getUri(), $key, $value);
            $request = $request->withUri($uri);
        }
        return $request;
    }