private function filterPath($path)
    {
        if ($path != null && substr($path, 0, 1) !== '/') {
            $path = '/' . $path;
        }

        return preg_replace_callback(
            '/(?:[^' . self::$charUnreserved . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
            function ($match) { return rawurlencode($match[0]); },
            $path
        );
    }