[Opensim-dev] Uris: Errors/Inconsistencies/TBD
Stefan Andersson
stefan at tribalmedia.se
Wed Sep 10 06:03:13 UTC 2008
Alan,
insensititvity is in deed best and often the goal.
Although, sometimes things are best explicit and sometimes best implicit. Knowing when and how is often a black art; a combination of ignorance, wishes, knowledge, experience and preference.
Uri, at least on .net, in deed adds a trailing slash:
// Yields http://www.sunet.se/
Console.WriteLine(new Uri("http://www.sunet.se").ToString());
So, the easy fix would be to let the RestClient strip any trailing slashes from the supplied base url.
When lloking thru the RestClient, I noticed some other things:
The rest client takes the url (set form the ini) - RestClient rc = new RestClient(_assetServerUrl);
The AddResourcePath only trims one slash from the end
_pathElements.Add(element.Substring(0, element.Length - 1));
which is a presumption; maybe better to use TrimStart() and TrimEnd() - or even better to just throw an exception saying "you shouldn't supply slashes, we take care of that"
In the RestClient, we build the uri ourselves (with query and fragments) from scratch, why not just depend on the UriBuilder where it provides what we need?
When we build the request, private Uri buildUri()
does
foreach (string e in _pathElements)
{
sb.Append("/");
sb.Append(e);
}
which presumes the root url to be slash-less
As said above, the easyfix(tm) would be to let the rest client trim off trailing slashes from the incoming root url.
Then again, the best approach would be to peruse Uri and UriBuilder internally,
and only supply the functionality that isn't already there.
on the issue of trilaing slashes, I do know that there is no 'right' answer, and that it's been subject to holy wars, but the trailing slash has the good benefit that the node itself definies explicitly whether it's referencing a file or a directory. (as opposed to the prefix notation which actually defines the node _before_ it to be a hierarchy node)
leaving this to the web server to figure out can lead to ambiguities and errors, especially when doing REST (ie, is that guid referencing a node or a leaf?) or writing parsing url rewriters.
so, in general, the trailing slash approach leads to less screw-up potential.
Best regards,Stefan AnderssonTribal Media AB Join the 3d web revolution : http://tribalnet.se/
To: opensim-dev at lists.berlios.deFrom: alan_webb at us.ibm.comDate: Tue, 9 Sep 2008 08:51:55 -0400Subject: Re: [Opensim-dev] Uris: Errors/Inconsistencies/TBDStefan Consistency would be nice, but I think insensitivity would be better. Can you give some specific examples, I trawled through the code but couldn't be sure i was finding the code you have issue with. In the REST code in ApplicationPlugins/Rest all inbound URL's are canonicalized to eliminate any issues WRT trailing "/". BTW as far as I can tell, The Uri class' ToString echoes whatever you provide. If you don't supply a trailing slash when the URI is created, then ToString does not generate one. The ABNF in RFC 3986 (URI Generic Syntax) always shows "/" as a prefixing notion - conversely, many of their textual examples indicate that a trailing "/" is perfectly valid. I think this is an area where human interaction will always produce either, and REST is certanly not limited to machine-to-machine communications, so I do think we need to code this is in a way that says it doesn't matter. Best regardsAlan-------------------T.J. Watson Research Center, Hawthorne, NY1-914-784-7286alan_webb at us.ibm.com
Stefan Andersson <stefan at tribalmedia.se> Sent by: opensim-dev-bounces at lists.berlios.de
09/09/2008 04:20 AM
Please respond toopensim-dev at lists.berlios.de
To
<opensim-dev at lists.berlios.de>
cc
Subject
[Opensim-dev] Uris: Errors/Inconsistencies/TBD
Just a quick one,I don't have time to fix this up, and I guess we should discuss it first;the issue is that parts of the code presumes url segments _ends_ with '/' and others they _begin_ with '/'this leads to heavy confusion and easily done mistakesnow, the Uri class (which, together with UriBuilder, is poorly underused) ToString _appends_ an '/'which I consider the proper behaviour: all segments appends an '/' to show they represent a hierarchy node.I've already made the inventoryUrl wrapping an Uri to safeguard against missing trailing '/' in the ini, which is/was one of our most common mistakes, it seems. (and a bloody easy one at that)Now, for example, the REST code, presumes the oppositewhich means we can't combine the output of a Uri with the output from the RestClient.So I can't wrap the asset url the same way.Which sucks.Either way, I suggest we use postfix notation in accordance with Uri class standard, but most of all I would want us to harmonize on one or the other.Discussions?/Stefan_______________________________________________Opensim-dev mailing listOpensim-dev at lists.berlios.dehttps://lists.berlios.de/mailman/listinfo/opensim-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://opensimulator.org/pipermail/opensim-dev/attachments/20080910/5af53406/attachment-0001.html>
More information about the Opensim-dev
mailing list