Storage/src/SigningHelper.php
private function normalizeHeaders(array $headers)
    {
        $out = [];
        foreach ($headers as $name => $value) {
            $name = strtolower(trim($name));
            // collapse arrays of values into a comma-separated list.
            if (!is_array($value)) {
                $value = [$value];
            }

            foreach ($value as &$headerValue) {
                // strip trailing and leading spaces.
                $headerValue = trim($headerValue);

                // replace newlines with empty strings.
                $headerValue = str_replace(PHP_EOL, '', $headerValue);

                // collapse multiple whitespace chars to a single space.
                $headerValue = preg_replace('/\s+/', ' ', $headerValue);
            }

            $out[$name] = implode(', ', $value);
        }

        return $out;
    }
private function normalizeHeaders(array $headers)
    {
        $out = [];
        foreach ($headers as $name => $value) {
            $name = strtolower(trim($name));
            // collapse arrays of values into a comma-separated list.
            if (!is_array($value)) {
                $value = [$value];
            }

            foreach ($value as &$headerValue) {
                // strip trailing and leading spaces.
                $headerValue = trim($headerValue);

                // replace newlines with empty strings.
                $headerValue = str_replace(PHP_EOL, '', $headerValue);

                // collapse multiple whitespace chars to a single space.
                $headerValue = preg_replace('/\s+/', ' ', $headerValue);
            }

            $out[$name] = implode(', ', $value);
        }

        return $out;
    }
private function normalizeHeaders ( array $ headers ) { $ out = [ ] ; foreach ( $ headers as $ name => $ value ) { $ name = strtolower ( trim ( $ name ) ) ; // collapse arrays of values into a comma-separated list. if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } foreach ( $ value as & $ headerValue ) { // strip trailing and leading spaces. $ headerValue = trim ( $ headerValue ) ; // replace newlines with empty strings. $ headerValue = str_replace ( PHP_EOL , '' , $ headerValue ) ; // collapse multiple whitespace chars to a single space. $ headerValue = preg_replace ( '/\s+/' , ' ' , $ headerValue ) ; } $ out [ $ name ] = implode ( ', ' , $ value ) ; } return $ out ; }
Cleans and normalizes header values.

Arrays of values are collapsed into a comma-separated list, trailing and
leading spaces are removed, newlines are replaced by empty strings, and
multiple whitespace chars are replaced by a single space.

@param array $headers Input headers
@return array
Cleans and normalizes header values .