private function filterMethod(?string $method): string
    {
        if ($method === null) {
            return self::METHOD_GET;
        }

        if (! \preg_match("/^[!#$%&'*+.^_`|~0-9a-z-]+$/i", $method)) {
            throw new InvalidArgumentException(\sprintf(
                'Unsupported HTTP method [%s].',
                $method
            ));
        }

        return $method;
    }