[webkit-dev] How to access resource meta-data

Darin Adler darin at apple.com
Wed Oct 29 09:42:04 PDT 2008

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:


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.

> 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]  
     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

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.

     -- Darin

More information about the webkit-dev mailing list