|
#import "NSHTTPCookieStorage+dump.h" |
|
|
|
@implementation NSHTTPCookieStorage (dump) |
|
|
|
- (void) dump { |
|
[self dumpWithMessage:nil forURL:nil]; |
|
} |
|
|
|
- (void) dumpForURL:(NSURL*)url { |
|
[self dumpWithMessage:nil forURL:url]; |
|
} |
|
|
|
- (void) dumpWithMessage:(NSString *)msgOrNil forURL:(NSURL*)url { |
|
if(url) msgOrNil = msgOrNil ? [msgOrNil stringByAppendingFormat:@" (%@)", url] : url.description; |
|
|
|
NSMutableString *cookieDescs = [[[NSMutableString alloc] init] autorelease]; |
|
NSHTTPCookie *cookie; |
|
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
|
NSArray *cookies = url ? [cookieJar cookiesForURL:url] : [cookieJar cookies]; |
|
for (cookie in cookies) { |
|
[cookieDescs appendString:[self cookieDescription:cookie]]; |
|
} |
|
NSLog(@"------ [Cookie Dump: %@] ---------\n%@", msgOrNil, cookieDescs); |
|
NSLog(@"----------------------------------"); |
|
} |
|
|
|
- (NSString *) cookieDescription:(NSHTTPCookie *)cookie { |
|
|
|
NSMutableString *cDesc = [[[NSMutableString alloc] init] autorelease]; |
|
[cDesc appendString:@"[NSHTTPCookie]\n"]; |
|
[cDesc appendFormat:@" name = %@\n", [[cookie name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; |
|
[cDesc appendFormat:@" value = %@\n", [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; |
|
[cDesc appendFormat:@" domain = %@\n", [cookie domain]]; |
|
[cDesc appendFormat:@" path = %@\n", [cookie path]]; |
|
[cDesc appendFormat:@" expiresDate = %@\n", [cookie expiresDate]]; |
|
[cDesc appendFormat:@" sessionOnly = %d\n", [cookie isSessionOnly]]; |
|
[cDesc appendFormat:@" secure = %d\n", [cookie isSecure]]; |
|
[cDesc appendFormat:@" comment = %@\n", [cookie comment]]; |
|
[cDesc appendFormat:@" commentURL = %@\n", [cookie commentURL]]; |
|
[cDesc appendFormat:@" version = %lu\n", (unsigned long)[cookie version]]; |
|
|
|
// [cDesc appendFormat:@" portList = %@\n", [cookie portList]]; |
|
// [cDesc appendFormat:@" properties = %@\n", [cookie properties]]; |
|
|
|
return cDesc; |
|
} |
|
|
|
@end |