[webkit-dev] How to access resource meta-data
Andrew S. Townley
ast at atownley.org
Wed Oct 29 14:14:40 PDT 2008
On Wed, 2008-10-29 at 09:42 -0700, Darin Adler wrote:
> On Oct 29, 2008, at 9:30 AM, Andrew S. Townley wrote:
>
> > Fair enough. What I'm looking for at a minimum is the headers
> > associated with each HTTP response.
>
> You'd get at those through the resource load delegate. When a resource
> is loaded the delegate receives an Objective-C method call, named:
>
> webView:resource:didReceiveResponse:fromDataSource:
>
> The response argument is an NSURLResponse object. After determining
> that it's an HTTP response, using -[NSObject isKindOfClass:] it can be
> cast to NSHTTPURLResponse and you can use methods such as -
> [NSHTTPURLResponse allHeaderFields] and -[NSHTTPURLResponse
> statusCode] on it.
Cool. Thanks. I know there are some patches for some of the delegates,
but I haven't applied them to my tree yet. I looked at some of the Curl
backend implementations, but I didn't see these exposed yet.
> > It would be nice to also be able to extract any HTML meta tags and
> > have access to those as well.
>
> That can be done with the DOM API. Something like this:
>
> DOMNodeList *metaElements = [[webView mainFrameDocument]
> getElementsByTagName:@"meta"];
> NSUInteger count = [metas length];
> for (NSUInteger i = 0; i < count; ++i) {
> DOMElement *metaElement = (DOMElement *)[metaElements item:i];
> NSString *nameAttribute = [metaElement getAttribute:@"name"];
> // ... more work here
> }
Yeah, true. I'm pretty familiar with using DOM for XML, but I was just
wondering the extent of some of the things already in place.
> FYI, some of the things you mentioned from the Firefox dialog are
> things that are either part of the networking library or part of the
> browser application proper, and not controlled or tracked by WebKit.
Again, just trying to establish what was there and what wasn't before I
spent too much time trying to roll my own solutions.
Thanks for your help.
ast
--
Andrew S. Townley <ast at atownley.org>
http://atownley.org
More information about the webkit-dev
mailing list