Ejemplo n.º 1
0
        /// <summary>
        /// A convenience method that creates a new
        /// <see cref="Sharpen.URI">Sharpen.URI</see>
        /// whose scheme, host, port, path,
        /// query are taken from the existing URI, dropping any fragment or user-information.
        /// The path is set to "/" if not explicitly specified. The existing URI is returned
        /// unmodified if it has no fragment or user-information and has a path.
        /// </summary>
        /// <param name="uri">original URI.</param>
        /// <exception cref="Sharpen.URISyntaxException">If the resulting URI is invalid.</exception>
        public static URI RewriteURI(URI uri)
        {
            Args.NotNull(uri, "URI");
            if (uri.IsOpaque())
            {
                return(uri);
            }
            URIBuilder uribuilder = new URIBuilder(uri);

            if (uribuilder.GetUserInfo() != null)
            {
                uribuilder.SetUserInfo(null);
            }
            if (TextUtils.IsEmpty(uribuilder.GetPath()))
            {
                uribuilder.SetPath("/");
            }
            if (uribuilder.GetHost() != null)
            {
                uribuilder.SetHost(uribuilder.GetHost().ToLower(Sharpen.Extensions.GetEnglishCulture()
                                                                ));
            }
            uribuilder.SetFragment(null);
            return(uribuilder.Build());
        }