Phly\Http\MessageTrait::withHeader PHP Method

withHeader() public method

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.
public withHeader ( $header, string | string[] $value ) : self
$value string | string[] Header value(s).
return self
    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;
    }