[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/4] Avoid duplicating cookies when loading from store
From: |
Lubomir Rintel |
Subject: |
[PATCH 2/4] Avoid duplicating cookies when loading from store |
Date: |
Mon, 6 Feb 2012 14:39:17 +0100 |
* Source/NSHTTPCookieStorage.m (_updateFromCookieStore):
Eliminate cookies that we are aready aware of.
---
Source/NSHTTPCookie.m | 12 +++++++++++-
Source/NSHTTPCookieStorage.m | 7 +++++--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/Source/NSHTTPCookie.m b/Source/NSHTTPCookie.m
index e8cd6bc..bbab3b1 100644
--- a/Source/NSHTTPCookie.m
+++ b/Source/NSHTTPCookie.m
@@ -299,7 +299,13 @@ static NSRange GSRangeOfCookie(NSString *string);
rawProps = [[properties mutableCopy] autorelease];
if ([rawProps objectForKey: @"Created"] == nil)
- [rawProps setObject: [NSDate date] forKey: @"Created"];
+ {
+ /* Round to whole seconds, so that it stays same ofter serialization
+ * into plist and deserialization and thus can be used to eliminate
duplicates.
+ */
+ NSInteger seconds = [[NSDate date] timeIntervalSinceReferenceDate];
+ [rawProps setObject: [NSDate
dateWithTimeIntervalSinceReferenceDate:seconds] forKey: @"Created"];
+ }
if ([rawProps objectForKey: NSHTTPCookieExpires] == nil
|| [[rawProps objectForKey: NSHTTPCookieExpires]
isKindOfClass: [NSDate class]] == NO)
@@ -357,6 +363,10 @@ static NSRange GSRangeOfCookie(NSString *string);
[self name], [self value]];
}
+- (BOOL) isEqual: (id)other
+{
+ return [[other properties] isEqual: [self properties]];
+}
@end
diff --git a/Source/NSHTTPCookieStorage.m b/Source/NSHTTPCookieStorage.m
index 5ac2762..2867282 100644
--- a/Source/NSHTTPCookieStorage.m
+++ b/Source/NSHTTPCookieStorage.m
@@ -176,8 +176,11 @@ static NSHTTPCookieStorage *storage = nil;
if (properties == nil)
return;
for (i = 0; i < [properties count]; i++)
- [this->_cookies addObject:
- [NSHTTPCookie cookieWithProperties: [properties objectAtIndex: i]]];
+ {
+ NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties: [properties
objectAtIndex: i]];
+ if (![this->_cookies containsObject:cookie])
+ [this->_cookies addObject:cookie];
+ }
}
- (void) _updateToCookieStore
--
1.7.1