Cache handling according to RFC 7232
This commit is contained in:
@@ -32,7 +32,6 @@ static int32_t const kDefaultFeedRefreshInterval = 30 * 60;
|
||||
- (void)setSucessfulWithResponse:(NSHTTPURLResponse*)response;
|
||||
// Setter
|
||||
- (void)setUrlIfChanged:(NSString*)url;
|
||||
- (void)setEtag:(NSString*)etag modified:(NSString*)modified;
|
||||
- (BOOL)setRefreshAndSchedule:(int32_t)refresh;
|
||||
- (void)scheduleNow:(NSTimeInterval)future;
|
||||
@end
|
||||
|
||||
@@ -54,7 +54,10 @@
|
||||
- (void)setSucessfulWithResponse:(NSHTTPURLResponse*)response {
|
||||
self.errorCount = 0; // reset counter
|
||||
NSDictionary *header = [response allHeaderFields];
|
||||
[self setEtag:header[@"Etag"] modified:header[@"Date"]]; // @"Expires", @"Last-Modified"
|
||||
if (response.statusCode != 304) { // not all servers set etag / modified when returning 304
|
||||
[self setEtag:header[@"Etag"] modified:header[@"Last-Modified"]];
|
||||
[self setUrlIfChanged:response.URL.absoluteString];
|
||||
}
|
||||
[self scheduleNow:self.refresh];
|
||||
}
|
||||
|
||||
|
||||
@@ -70,9 +70,10 @@ static _Atomic(NSUInteger) _queueSize = 0;
|
||||
+ (NSURLRequest*)newRequest:(FeedMeta*)meta ignoreCache:(BOOL)flag {
|
||||
NSMutableURLRequest *req = [self newRequestURL:meta.url];
|
||||
if (!flag) {
|
||||
// Both fields should be sent (if server provides both) RFC: https://tools.ietf.org/html/rfc7232#section-2.4
|
||||
if (meta.etag.length > 0)
|
||||
[req setValue:meta.etag forHTTPHeaderField:@"If-None-Match"]; // ETag
|
||||
else if (meta.modified.length > 0)
|
||||
if (meta.modified.length > 0)
|
||||
[req setValue:meta.modified forHTTPHeaderField:@"If-Modified-Since"];
|
||||
}
|
||||
if (!_requestsAreUrgent) // any request that is not forced, is a background update
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>11387</string>
|
||||
<string>11491</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.news</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@@ -83,4 +83,6 @@
|
||||
}];
|
||||
}
|
||||
|
||||
// x-apple.systempreferences:com.apple.preferences.users?startupItemsPref
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user