Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Created January 29, 2013 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daij-Djan/4662895 to your computer and use it in GitHub Desktop.
Save Daij-Djan/4662895 to your computer and use it in GitHub Desktop.
dump cookies that are stored in a NSHTTPCookie storage instance. typically you use `[[NSHTTPCookieStorage sharedHTTPCookieStorage] dump];` All credits go to bladnman @ http://stackoverflow.com/questions/771498/where-are-an-uiwebviews-cookies-stored
@interface NSHTTPCookieStorage (dump)
- (void) dump;
- (void) dumpForURL:(NSURL*)url;
- (void) dumpWithMessage:(NSString *)msgOrNil forURL:(NSURL*)url;
@end
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment