src/MessageTrait.php
public function withHeader($header, $value)
    {
        if (is_string($value)) {
            $value = [ $value ];
        }

        if (! is_array($value) || ! $this->arrayContainsOnlyStrings($value)) {
            throw new InvalidArgumentException(
                'Invalid header value; must be a string or array of strings'
            );
        }

        HeaderSecurity::assertValidName($header);
        self::assertValidHeaderValue($value);

        $normalized = strtolower($header);

        $new = clone $this;

        $new->headerNames[$normalized] = $header;
        $new->headers[$header] = $value;
        return $new;
    }
public function withHeader($header, $value)
    {
        if (is_string($value)) {
            $value = [ $value ];
        }

        if (! is_array($value) || ! $this->arrayContainsOnlyStrings($value)) {
            throw new InvalidArgumentException(
                'Invalid header value; must be a string or array of strings'
            );
        }

        HeaderSecurity::assertValidName($header);
        self::assertValidHeaderValue($value);

        $normalized = strtolower($header);

        $new = clone $this;

        $new->headerNames[$normalized] = $header;
        $new->headers[$header] = $value;
        return $new;
    }
public function withHeader ( $ header , $ value ) { if ( is_string ( $ value ) ) { $ value = [ $ value ] ; } if ( ! is_array ( $ value ) || ! $ this -> arrayContainsOnlyStrings ( $ value ) ) { throw new InvalidArgumentException ( 'Invalid header value; must be a string or array of strings' ) ; } HeaderSecurity :: assertValidName ( $ header ) ; self :: assertValidHeaderValue ( $ value ) ; $ normalized = strtolower ( $ header ) ; $ new = clone $ this ; $ new -> headerNames [ $ normalized ] = $ header ; $ new -> headers [ $ header ] = $ value ; return $ new ; }
Return an instance with the provided header, replacing any existing
values of any headers with the same case-insensitive name.

While header names are case-insensitive, the casing of the header will
be preserved by this function, and returned from getHeaders().

This method MUST be implemented in such a way as to retain the
immutability of the message, and MUST return an instance that has the
new and/or updated header and value.

@param string $name Case-insensitive header field name.
@param string|string[] $value Header value(s).
@return self
@throws \InvalidArgumentException for invalid header names or values.
Return an instance with the provided header replacing any existing values of any headers with the same case - insensitive name .