Calculate/determine the required headers for the request.

@param RequestInterface $request

@return string[] The headers for the request
555521
private function createHeaders(RequestInterface $request)
    {
        $nonce = $this->nonceGenerator->generate();
        $timestamp = $this->timestampGenerator->generate();

        /** @var array $data */
        $data = $this->createDataElement($request, $nonce, $timestamp);

        $payload = $request->getMethod() .
            '&' . rawurlencode((string)$request->getUri()) .
            '&' . implode(rawurlencode('&'), $data);

        $signkey = rawurlencode($this->key) . '&' . rawurlencode($this->secret);
        $hash = rawurlencode(base64_encode(hash_hmac('sha256', $payload, $signkey)));

        /** @var array $oauth_header */
        $oauth_header = $this->createOAuthHeaders($nonce, $timestamp, $hash);

        $header = [];
        $header['Content-type'] = 'application/json';
        $header['Authorization'] = 'OAuth ' . implode(', ', $oauth_header);

        return $header;
    }
1179723
protected function createCurlSettingsArray(RequestInterface $request): array
    {
        $settings = $this->curlSettings;

        switch ($request->getMethod()) {
            case 'HEAD':
                $settings[CURLOPT_NOBODY] = true;
                $settings[CURLOPT_CUSTOMREQUEST] = 'HEAD';
                break;
            case 'GET':
                $settings[CURLOPT_CUSTOMREQUEST] = 'GET';
                break;
            default:
                $body = $request->getBody();
                if (is_resource($body)) {
                    // This needs to be set to PUT, regardless of the actual
                    // method used. Without it, INFILE will be ignored for some
                    // reason.
                    $settings[CURLOPT_PUT] = true;
                    $settings[CURLOPT_INFILE] = $request->getBody();
                } else {
                    // For security we cast this to a string. If somehow an array could
                    // be passed here, it would be possible for an attacker to use @ to
                    // post local files.
                    $settings[CURLOPT_POSTFIELDS] = (string) $body;
                }
                $settings[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
                break;
        }

        $nHeaders = [];
        foreach ($request->getHeaders() as $key => $values) {
            foreach ($values as $value) {
                $nHeaders[] = $key.': '.$value;
            }
        }
        $settings[CURLOPT_HTTPHEADER] = $nHeaders;
        $settings[CURLOPT_URL] = $request->getUrl();
        // FIXME: CURLOPT_PROTOCOLS is currently unsupported by HHVM
        if (defined('CURLOPT_PROTOCOLS')) {
            $settings[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
        }
        // FIXME: CURLOPT_REDIR_PROTOCOLS is currently unsupported by HHVM
        if (defined('CURLOPT_REDIR_PROTOCOLS')) {
            $settings[CURLOPT_REDIR_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
        }

        return $settings;
    }
1083855
public function sign(RequestInterface $request)
    {
        $oAuthParams = array_merge(
            $this->getDefaultOAuthParams(),
            ['oauth_signature_method' => $this->signatureMethod->getName()]
        );

        $oAuthParams['oauth_signature'] = $this->signatureMethod->buildSignature(
            $request,
            $oAuthParams,
            $this->consumer,
            $this->token
        );

        return $request->withHeader(
            'authorization',
            $this->buildAuthorizationHeader($oAuthParams)
        );
    }
106025
public function applyToRequest(RequestInterface $request)
    {
        $body = $this->streamFactory->createStream((string) $this->queryHelper);

        return $request
            ->withBody($body)
            ->withHeader('Content-Type', 'application/x-www-form-urlencoded');
    }
1175444
private function setOAuthHeaders(RequestInterface $request): RequestInterface
    {
        $now = new \DateTime();
        if ($this->now instanceof \DateTime) {
            $now = clone $this->now;
        }

        //Generate HTTP headers
        $encodedKey = \rawurlencode($this->oauthConsumerSecret).'&'.\rawurlencode($this->oauthAccessTokenSecret);
        $oauthParams = [
            'oauth_consumer_key' => $this->oauthConsumerKey,
            'oauth_token' => $this->oauthAccessToken,
            'oauth_nonce' => \sha1(\microtime(true).\rand(10000, 99999)),
            'oauth_timestamp' => $now->getTimestamp(),
            'oauth_signature_method' => 'PLAINTEXT',
            'oauth_version' => '1.0',
            'oauth_signature' => $encodedKey,
        ];

        $request = $request->withHeader('Authorization', $this->encodeOAuthHeaders($oauthParams));

        return $request->withHeader('Expect', '');
    }
535695
public function getToolSessionDataFromRequest(RequestInterface $request)
	{
		// get params via post vars
		$toolSessionId    = $request->request('sessionnum');
		$toolSessionToken = $request->request('sessiontoken');

		// use headers as backup method to post vars
		if (!$toolSessionId && !$toolSessionToken)
		{
			$toolSessionId    = $request->headers('sessionnum');
			$toolSessionToken = $request->headers('sessiontoken');
		}

		// return id & token
		return compact('toolSessionId', 'toolSessionToken');
	}
169150
protected function transformRequestHeadersToString(RequestInterface $request): string
    {
        $message = vsprintf('%s %s HTTP/%s', [
            strtoupper($request->getMethod()),
            $request->getRequestTarget(),
            $request->getProtocolVersion(),
        ])."\r\n";

        foreach ($request->getHeaders() as $name => $values) {
            $message .= $name.': '.implode(', ', $values)."\r\n";
        }

        $message .= "\r\n";

        return $message;
    }
175100
protected function authentication(RequestInterface $request)
	{
		if ($this->tokenRequired)
		{
			return $request->withHeader('Authorization', sprintf('OAuth %s', $this->getAccessToken()));
		}

		return $request;
	}
364042
public function onRequest( RequestInterface $request ) {
        $localizedUri = Uri::withQueryValue( $request->getUri(), 'lang', $this->getEndpoint()->getLang() );
        return $request->withUri($localizedUri);
    }
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;
    }
149970
private function getAggregations(RequestInterface $request)
    {
        $aggregations = [];

        if ($request->getAggregation()) {
            $aggregations = $this->aggregationBuilder->buildAggregations($request->getAggregation());
        }

        return $aggregations;
    }
103573
public function renderIntoCookieHeader(RequestInterface $request) : RequestInterface
    {
        $cookieString = implode('; ', $this->cookies);

        $request = $request->withHeader(static::COOKIE_HEADER, $cookieString);

        return $request;
    }
110930
protected static function getKey(RequestInterface $request)
    {
        // Generate headerline for the cache key. X- headers are ignored except those included in the Vary
        $vary = array_flip($request->getHeader('Vary'));
        $headerLine = implode('', array_map(
            [$request, 'getHeaderLine'],
            array_filter(
                array_keys($request->getHeaders()),
                function ($header) use ($vary) {
                    return (0 !== stripos($header, 'x-')
                        || array_key_exists($header, $vary)
                    );
                }
            )
        ));

        return $request->getMethod().'-'.$request->getUri().'-'.md5($headerLine);
    }
1316945
private function query(RequestInterface $request)
    {
        return $this->client->send($request, array_merge(
            [RequestOptions::HTTP_ERRORS => false],
            $this->clientOptions
        ));
    }
661176
public static function determineAcceptedMediaTypes(RequestInterface $request): array
    {
        $rawValues = $request->getHeader('Accept');
        if (empty($rawValues) || !is_string($rawValues)) {
            return ['*/*'];
        }
        $acceptedMediaTypes = self::parseContentNegotiationQualityValues($rawValues);

        return $acceptedMediaTypes;
    }
805939
public function send(RequestInterface $request)
	{
		$request = $this->authentication($request);
		$defaultHeaders = [
			'Accept'       => $this->getContentType(),
			'Content-Type' => $this->getContentType()
		];

		foreach ($defaultHeaders as $defaultHeader => $value)
		{
			if ( ! $request->hasHeader($defaultHeader))
			{
				$request = $request->withHeader($defaultHeader, $value);
			}
		}

		$response = $this->client->sendRequest($request);
		$response = $this->transformResponseToException($request, $response);

		return $response;
	}
664794
protected function processing(RequestInterface $request)
    {
        $key = sprintf(
            '%s?%s',
            $request->getUri()->getPath(),
            $request->getUri()->getQuery()
        );

        if ($request->getMethod() == 'GET' && isset($this->data[$key])) {
            return $this->data[$key];
        }

        return null;
    }