protected function formatUri($uri): string
    {
        $scheme = $uri->getScheme();
        if ('' != $scheme) {
            $scheme = $scheme.':';
        }

        $authority = null;
        $host = $uri->getHost();
        if ('' != $host) {
            $user_info = $uri->getUserInfo();
            if ('' != $user_info) {
                $authority .= (new UserInfo())->withContent($user_info)->getContent($this->enc_type).'@';
            }
            $authority .= (new Host($host))->getContent($this->enc_type);
            $port = $uri->getPort();
            if (null !== $port) {
                $authority .= ':'.$port;
            }
        }

        if (null !== $authority) {
            $authority = '//'.$authority;
        }

        $path = (new Path($uri->getPath()))->getContent($this->enc_type);
        if (null !== $authority && '' !== $path && '/' !== $path[0]) {
            $path = '/'.$path;
        }

        $query = $uri->getQuery();
        if ('' != $query || $this->preserve_query) {
            $query = '?'.Uri\build_query(Uri\parse_query($query), $this->query_separator, $this->enc_type);
        }

        $fragment = $uri->getFragment();
        if ('' != $fragment || $this->preserve_fragment) {
            $fragment = '#'.(new Fragment($fragment))->getContent($this->enc_type);
        }

        return $scheme.$authority.$path.$query.$fragment;
    }