@param $headers

@return array
@throws AuthorizeException
486685
private function prepareHeaders($headers)
    {
        $headers = array_merge($this->defaultHeaders, $headers);

        if ($this->shopId && $this->shopPassword) {
            $encodedAuth              = base64_encode($this->shopId.":".$this->shopPassword);
            $headers["Authorization"] = "Basic ".$encodedAuth;
        } else if ($this->bearerToken) {
            $headers["Authorization"] = 'Bearer '.$this->bearerToken;
        }

        if (empty($headers['Authorization'])) {
            throw new AuthorizeException('Authorization headers not set');
        }

        $headers = array_map(function ($key, $value) {
            return $key.":".$value;
        }, array_keys($headers), $headers);


        return $headers;
    }
1075431
protected function normalizeHeaders(array $headers) : array
    {
        $returnHeaders = [];
        foreach ($headers as $key => $header) {
            $returnHeaders[$key] = $header[0] ?? $header;
        }

        return $returnHeaders;
    }
395230
public function headersToCurl(array $headers)
    {
        $this->formatedParameters = [];
        $curlHeaders              = '';

        foreach ($headers as $headerName => $values) {
            foreach ($values as $headerValue) {
                $curlHeaders .= sprintf('--header "%s: %s" ', $headerName, $headerValue);
            }
        }

        return substr($curlHeaders, 0, -1);
    }
357025
protected function getHeaderArray(string $headers): array
    {
        $headerArray  = [];
        $headersArray = explode("\r\n", trim($headers));
        foreach ($headersArray as $line => $header) {
            if ($line > 0) {
                $pair                    = explode(': ', $header);
                $headerArray[$pair[0]][] = $pair[1];
            } else {
                $headerArray['status'][] = $header;
            }
        }

        return $headerArray;
    }
297907
protected function setHeaders(array $headers)
    {
        $this->headers = [];
        
        foreach ($headers as $name => $values) {
            $this->assertHeaderName($name);
            $this->assertHeaderValue($values);
        
            $key = strtolower($name);
            $this->headers[$key] = ['name' => $name, 'values' => (array)$values];
        }
    }
718281
public function getAuthorizationHeader($url, array $params, array $overrides = [])
    {
        $headers = $this->prepareHeaders('POST', $url, $params, $overrides);

        $headers = implode(',', array_map(function($name, $value){
            return sprintf('%s="%s"', $name, $value);
        }, array_keys($headers), $headers));

        return sprintf('OAuth realm="",%s', $headers);
    }
1182849
protected function mapHeaders(array $headers)
    {
        $mappedHeaders = array();
        foreach ($headers as $headerPair) {
            list($name, $value) = $headerPair;
            $mappedHeaders[strtolower($name)] = $value;
        }

        return $mappedHeaders;
    }
157026
public static function parseHeaders(string $headers): array
    {
        $res = [];

        foreach (explode("\r\n", $headers) as $line) {
            $line = trim($line);
            if (!$line) {
                continue;
            }

            $line = explode(': ', $line);
            if (count($line) !== 2) {
                continue;
            }

            $res[strtolower($line[0])] = $line[1];
        }

        return $res;
    }
1229294
protected function mapHeaderKeys(array $headers)
    {
        $phpHeaders = array();
        foreach ($headers as $key => $value) {
            $phpHeaders['HTTP_' . str_replace('-', '_', strtoupper($key))] = $value;
        }

        return $phpHeaders;
    }
1194376
private function determineHeaderStringForSignedResponse(array $headers)
    {
        $signedDataHeaders = [];
        ksort($headers);

        foreach ($headers as $headerName => $headerValue) {
            // All headers with the prefix 'X-Bunq-' except 'Server-Signature' need to be signed.
            $headerName = $this->ensureHeaderIsCorrectlyCased($headerName);

            if ($headerName === self::HEADER_SERVER_SIGNATURE) {
                // Skip this header
            } elseif (strpos($headerName, self::HEADER_PREFIX) === self::HEADER_PREFIX_START) {
                $signedDataHeaders[] = $this->determineHeaderStringLine($headerName, $headerValue);
            }
        }

        return implode(self::NEWLINE, $signedDataHeaders);
    }
806690
public function getMetadataArray(array $headers)
    {
        $metadata = [];
        foreach ($headers as $key => $value) {
            $isMetadataHeader = Utilities::startsWith(
                strtolower($key),
                Resources::X_MS_META_HEADER_PREFIX
            );

            if ($isMetadataHeader) {
                $MetadataName = str_replace(
                    Resources::X_MS_META_HEADER_PREFIX,
                    Resources::EMPTY_STRING,
                    strtolower($key)
                );

                $metadata[$MetadataName] = $value;
            }
        }

        return $metadata;
    }
1059964
public function getRequestHeaders($auth = true)
    {
        $headers = \getallheaders();
        if($auth) {
            $hmac = $this->getRest()->getServer()->getHmac();
            $return = array(
                $hmac->getPrefix().'timestamp' => (isset($headers[$hmac->getPrefix().'timestamp']) ? $headers[$hmac->getPrefix().'timestamp'] : ''),
                $hmac->getPrefix().'signature' => (isset($headers[$hmac->getPrefix().'signature']) ? $headers[$hmac->getPrefix().'signature'] : ''),
                $hmac->getPrefix().'key' => (isset($headers[$hmac->getPrefix().'key']) ? $headers[$hmac->getPrefix().'key'] : ''),
                $hmac->getPrefix().'version' => (isset($headers[$hmac->getPrefix().'version']) ? $headers[$hmac->getPrefix().'version'] : ''),
            );
            $headers = $return;
        }
        
        return $headers;
    }
258920
protected function transformHeadersToServerVars(array $headers)
    {
        $server = [];
        $prefix = 'HTTP_';

        foreach ($headers as $name => $value) {
            $name = strtr(strtoupper($name), '-', '_');

            if (! Str::startsWith($name, $prefix) && $name != 'CONTENT_TYPE') {
                $name = $prefix.$name;
            }

            $server[$name] = $value;
        }

        return $server;
    }
953972
public static function decode(array $headers = []): array
    {
        $encodedHeaders = [];
        $encodedProperties = [];
        $prefixLength = strlen(self::PROPERTY_PREFIX);

        // separate headers/properties
        foreach ($headers as $key => $value) {
            if (0 === strpos($key, self::PROPERTY_PREFIX)) {
                $encodedProperties[substr($key, $prefixLength)] = $value;
            } else {
                $encodedHeaders[$key] = $value;
            }
        }

        $decodedHeaders = self::doDecode($encodedHeaders);
        $decodedProperties = self::doDecode($encodedProperties);

        return [$decodedHeaders, $decodedProperties];
    }
182274
private function processGetParams($headers)
    {
        $paramStrings = [];
        foreach ($headers['body'] as $key => $value) {
            $paramStrings[] = $key . "=" . $value;
        }
        $paramString = "?";
        $paramString .= implode("&", $paramStrings);

        return $paramString;
    }
1374112
protected function getHeadersAsString(array $headers)
    {
        $rawHeaders = [];

        foreach ($headers as $name => $header) {
            $rawHeaders[] = sprintf('%s: %s', trim($name), trim($header));
        }

        $rawHeaders = implode("\r\n", $rawHeaders);

        return $rawHeaders;
    }
861431
public static function getSignature($headers)
    {
        foreach($headers as $name => $value)
        {
            if(preg_match('/X-OpenPayU-Signature/i', $name) || preg_match('/OpenPayu-Signature/i', $name))
                return $value;
        }

        return null;
    }