[OGo-Developer] NSURL different in libFoundation and GNUstep base?
Sebastian Reitenbach
developer@opengroupware.org
Sun, 13 Apr 2008 16:41:24 +0200
developer@opengroupware.org wrote:
> On 13.04.2008, at 09:16, Sebastian Reitenbach wrote:
> > i try to create a NSURL and then to retrieve some data from it. This
> > is
> > working with my test program on gnustep-base, but not with
> > libFoundation.
>
> lF itself has no HTTP support. You can use WOHTTPConnection,
> WORequest, WOResponse.
what a mess, then i need to look at these classes...
>
> > URLString = [URLString
> > stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
>
> Convention is to use lowercase names for variables, eg:
> urlString
>
next time.
> For escaping you can find NSString methods in NGExtensions (those work
> on all Foundations).
>
> > Apr 13 07:00:50 getcoords [13768]: -[NSURL URLHandleUsingCache:]:
> > missing
> > handler for URL '<_NSAbsoluteHTTPURL
> ^^^error
>
> > libFoundation adds a :80 to the end of the URL, I wonder why, and
> > whether
> > this is the problem?
>
> Because your escaping code is b0rked. You escape almost the whole URL:
>
> URLString = [URLString stringByEscapingURL];
> URLString = [@"http://" stringByAppendingString:URLString];
>
> How is that supposed to work? (you put everything in the hostname ...)
at least that stringByAddingPercentEscapesUsingEncoding worked for me on the
whole uri string in gnustep-base, I did assume something equivalent happen
with stringByEscapingURL.
Unfortunately, regarding the stringByAddingPercentEscapesUsingEncoding, I
only find a comment in NSString+URLEscaping.m:
/*
TODO: support new Panther API?:
- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)e
- (NSString *)stringByReplacingPercentEscapesUsingEncoding:
(NSStringEncoding)e
*/
so I just added the stringByAddingPercentEscapesUsingEncoding to
NSString+URLEscaping.m. (cut 'n paste from gnustep), works now on the whole
string, the same way as in gnustep ;).
I could also add the stringByReplacingPercentEscapesUsingEncoding, and then
open an enhancement request, including a patch. As both libraries have
compatible licenses, I think that shouldn't be too much a problem.
However, in gnustep-base, these methods are found in NSString.m, where would
be the best place in libFoundation?
>
> You always need to escape the components of an URL individually. This
> is also true for the path, btw (escaping the whole path will escape
> the '/', hence, it will result in a single resource name!).
ah, ok, good to know.
cheers
Sebastian