private function filterHeader($values): array
    {
        if (!is_array($values)) {
            $values = [$values];
        }

        $lines = [];

        foreach ($values as $value) {
            if (is_numeric($value) || is_null($value) || (is_object($value) && method_exists($value, '__toString'))) {
                $value = (string) $value;
            } elseif (!is_string($value)) {
                throw new InvalidHeaderException('Header values must be strings or an array of strings.');
            }

            if (preg_match("/[^\t\r\n\x20-\x7e\x80-\xfe]|\r\n/", $value)) {
                throw new InvalidHeaderException('Invalid character(s) in header value.');
            }

            $lines[] = $value;
        }

        return $lines;
    }