/// <summary> /// Convert a Uri to a host local Uri, if possible. /// </summary> /// <remarks> /// Will return the original Uri if there is no local equivalent. /// </remarks> /// <param name="uri">Uri to convert.</param> /// <returns>Local Uri.</returns> public XUri AsLocalUri(XUri uri) { XUri result = uri; if (uri.Similarity(PublicUri) == PublicUri.MaxSimilarity) { result = uri.ChangePrefix(PublicUri, Env.LocalMachineUri); } else if ((ServerUri != null) && (uri.Similarity(ServerUri) == ServerUri.MaxSimilarity)) { result = uri.ChangePrefix(ServerUri, Env.LocalMachineUri); } return(result); }
public void ChangePrefix_does_not_work_with_http_and_https_using_strict() { var fromUri = new XUri("http://foo/from"); var toUri = new XUri("http://foo/to"); var uri = new XUri("https://foo/from/a/b/c"); var result = uri.ChangePrefix(fromUri, toUri, true); Assert.AreNotEqual("http://foo/to/a/b/c", result.ToString()); }
public void ChangePrefix_works_with_http_and_https() { var fromUri = new XUri("http://foo/from"); var toUri = new XUri("http://foo/to"); var uri = new XUri("https://foo/from/a/b/c"); var result = uri.ChangePrefix(fromUri, toUri); Assert.AreEqual("http://foo/to/a/b/c", result.ToString()); }
/// <summary> /// Convert a Uri to uri relative to the server's public uri, if possible. /// </summary> /// <remarks> /// Will return the original Uri if there is no public equivalent. /// </remarks> /// <param name="uri">Uri to convert.</param> /// <returns>Public Uri.</returns> public XUri AsServerUri(XUri uri) { XUri result = uri; if ((ServerUri != null) && (uri.Similarity(Env.LocalMachineUri) == Env.LocalMachineUri.MaxSimilarity)) { result = uri.ChangePrefix(Env.LocalMachineUri, ServerUri); } return(result); }
/// <summary> /// Convert a Uri to uri relative to the requests public uri, if possible. /// </summary> /// <remarks> /// Will return the original Uri if there is no public equivalent. /// </remarks> /// <param name="uri">Uri to convert.</param> /// <returns>Public Uri.</returns> public XUri AsPublicUri(XUri uri) { XUri result = uri; if (uri.Similarity(Env.LocalMachineUri) == Env.LocalMachineUri.MaxSimilarity) { result = uri.ChangePrefix(Env.LocalMachineUri, PublicUri); } return(result); }
private XUri GetPublicUri() { // Note (arnec): This is not the same as AsPublicUri, since we do this independently of a DreamContext XUri uri = Uri; if ((uri != null) && (_publicUri != null) && (_localMachineUri != null) && uri.HasPrefix(_localMachineUri)) { uri = uri.ChangePrefix(_localMachineUri, _publicUri); } return(uri); }