// static
LLURI LLURI::buildHTTP(const std::string& prefix,
                       const LLSD& path)
{
    LLURI result;

    // TODO: deal with '/' '?' '#' in host_port
    if (prefix.find("://") != prefix.npos)
    {
        // it is a prefix
        result = LLURI(prefix);
    }
    else
    {
        // it is just a host and optional port
        result.mScheme = "http";
        result.mEscapedAuthority = escapeHostAndPort(prefix);
    }

    if (path.isArray())
    {
        // break out and escape each path component
        for (LLSD::array_const_iterator it = path.beginArray();
                it != path.endArray();
                ++it)
        {
            LL_DEBUGS() << "PATH: inserting " << it->asString() << LL_ENDL;
            result.mEscapedPath += "/" + escapePathComponent(it->asString());
        }
    }
    else if (path.isString())
    {
        std::string pathstr(path);
        // Trailing slash is significant in HTTP land. If caller specified,
        // make a point of preserving.
        std::string last_slash;
        std::string::size_type len(pathstr.length());
        if (len && pathstr[len-1] == '/')
        {
            last_slash = "/";
        }

        // Escape every individual path component, recombining with slashes.
        for (boost::split_iterator<std::string::const_iterator>
                ti(pathstr, boost::first_finder("/")), tend;
                ti != tend; ++ti)
        {
            // Eliminate a leading slash or duplicate slashes anywhere. (Extra
            // slashes show up here as empty components.) This test also
            // eliminates a trailing slash, hence last_slash above.
            if (! ti->empty())
            {
                result.mEscapedPath
                += "/" + escapePathComponent(std::string(ti->begin(), ti->end()));
            }
        }

        // Reinstate trailing slash, if any.
        result.mEscapedPath += last_slash;
    }
    else if(path.isUndefined())
    {
        // do nothing
    }
    else
    {
        LL_WARNS() << "Valid path arguments to buildHTTP are array, string, or undef, you passed type"
                   << path.type() << LL_ENDL;
    }
    result.mEscapedOpaque = "//" + result.mEscapedAuthority +
                            result.mEscapedPath;
    return result;
}