Re: NSURL/NSURLHandle and caching
Re: NSURL/NSURLHandle and caching
- Subject: Re: NSURL/NSURLHandle and caching
- From: Dan Wood <email@hidden>
- Date: Tue, 27 Nov 2001 21:06:01 -0800
I feel your pain! I've been using NSURLHandle enough to know
where you're coming from.
First of all, I'd *highly* suggest that you log this as a bug at
bugreport.apple.com. This really ought to be solved, somehow,
by designing things such that this silliness won't happen. If
you log it as a bug, it will likely get onto the appropriate
person's to-do list.
As a work-around, you might want to think about subclassing
NSURLHandle to cache just the headers somehow. I haven't
thought through much of how to do this, but it might work.
Another approach is to use CURLHandle
<
http://curlhandle.sourceforge.net/>, which is a subclass of
NSURLHandle that makes use of CURL. This has a lot better
support for heads and bodies, and you should be able to coax it
to do what you want. (And if it needs some changes to allow
this, that would be easy since all the source is freely
available.)
Dan Wood
On Tuesday, November 27, 2001, at 07:22 PM, Tom Waters wrote:
i am struggling with NSURLHandle's propertyForKey: method.
i would expect that i could create an URL, get a handle to it,
get the resource data, then query the properties to see things
like the return codes, (for example 304 Not Modified and 404
Not Found).
if you use URLHandleUsingCache:YES this is indeed the behavior.
however, i need to NOT use the cache and make the request once
each time.
the problem is, if I get an URLHandleUsingCache:NO, the
subsequent propertyForKey: call does ANOTHER HTTP request.
this time with HEAD instead of GET, but of course, that
destroys the previous call's return code... this defeating the
purpose!
i even tried using the "UsingCache:YES" version and calling
[handle flushCachedData] afterwards, but it had no effect.
it's hard to describe what i'm trying to do, other than be a
reasonable http client... here's some code torn out of my app,
which may or may not make sense...
if you watch the server side of this (point it at say
localhost), you can see that the propertyForKey calls are
causing NSURL to do a subsequent HEAD call... if you change
the NO to a YES, it does exactly one GET, and will never do it
again, no matter if i flushCachedData or not.
- (void)get
{
NSURL *url = [NSURL URLWithString:@"http://www.apple.com/index.html"];
NSURLHandle *handle = [url URLHandleUsingCache:NO];
NSData *data;
id lastmod, lastmodString;
id code, reason;
[handle writeProperty:@"MyApp/1.0" forKey:@"User-Agent"];
[handle writeProperty:strlastmod forKey:@"If-Modified-Since"];
data = [handle resourceData];
code = [handle propertyForKey:NSHTTPPropertyStatusCodeKey];
reason = [handle propertyForKey:NSHTTPPropertyStatusReasonKey];
NSLog(@"%@ %@ %@", rel_path, code, reason);
lastmodString = [handle propertyForKey:@"Last-Modified"];
[handle flushCachedData];
}
does anyone (at apple?) have an opinion as to if i am doing
something wrong, or i should just bail on NSURL/NSURLHandle and
write my own client side using SmallSockets?
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
--
Dan Wood
email@hidden
http://www.karelia.com/
http://www.bikealameda.org/
Mac OS X Developer: Online Resume:
http://www.karelia.com/resume.html