public static function formatHeaders(array $headers): string
    {
        $buffer = "";
        $lines = 0;

        foreach ($headers as $name => $values) {
            // PHP casts integer-like keys to integers
            $name =  (string) $name;

            // Ignore any HTTP/2 pseudo headers
            if ($name[0] === ":") {
                continue;
            }

            /** @var array $values */
            foreach ($values as $value) {
                $buffer .= "{$name}: {$value}\r\n";
                $lines++;
            }
        }

        $count = \preg_match_all(self::HEADER_REGEX, $buffer);

        if ($lines !== $count || $lines !== \substr_count($buffer, "\n")) {
            throw new InvalidHeaderException("Invalid headers");
        }

        return $buffer;
    }
public static function formatHeaders(array $headers): string
    {
        $buffer = "";
        $lines = 0;

        foreach ($headers as $name => $values) {
            // PHP casts integer-like keys to integers
            $name =  (string) $name;

            // Ignore any HTTP/2 pseudo headers
            if ($name[0] === ":") {
                continue;
            }

            /** @var array $values */
            foreach ($values as $value) {
                $buffer .= "{$name}: {$value}\r\n";
                $lines++;
            }
        }

        $count = \preg_match_all(self::HEADER_REGEX, $buffer);

        if ($lines !== $count || $lines !== \substr_count($buffer, "\n")) {
            throw new InvalidHeaderException("Invalid headers");
        }

        return $buffer;
    }
public static function formatHeaders ( array $ headers ) : string { $ buffer = "" ; $ lines = 0 ; foreach ( $ headers as $ name => $ values ) { // PHP casts integer-like keys to integers $ name = ( string ) $ name ; // Ignore any HTTP/2 pseudo headers if ( $ name [ 0 ] === ":" ) { continue ; } /** @var array $values */ foreach ( $ values as $ value ) { $ buffer .= "{$name}: {$value}\r\n" ; $ lines ++ ; } } $ count = \ preg_match_all ( self :: HEADER_REGEX , $ buffer ) ; if ( $ lines !== $ count || $ lines !== \ substr_count ( $ buffer , "\n" ) ) { throw new InvalidHeaderException ( "Invalid headers" ) ; } return $ buffer ; }
Format headers in to their on-the-wire format.

Headers are always validated syntactically. This protects against response splitting and header injection
attacks.

@param array $headers Headers in a format as returned by {@see parseHeaders()}.

@return string Formatted headers.

@throws InvalidHeaderException If header names or values are invalid.
Format headers in to their on - the - wire format .