Cache handling according to RFC 7232

This commit is contained in:
relikd
2019-08-21 10:42:02 +02:00
parent e7dbfa5770
commit eb32ca9617
6 changed files with 122 additions and 4 deletions

View File

@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54ACC27B21061B3B0020715F"
BuildableName = "baRSS.app"
BlueprintName = "baRSS"
ReferencedContainer = "container:baRSS.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54ACC27B21061B3B0020715F"
BuildableName = "baRSS.app"
BlueprintName = "baRSS"
ReferencedContainer = "container:baRSS.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
stopOnEveryMainThreadCheckerIssue = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54ACC27B21061B3B0020715F"
BuildableName = "baRSS.app"
BlueprintName = "baRSS"
ReferencedContainer = "container:baRSS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-com.apple.CoreData.SQLDebug 4"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-com.apple.CoreData.ConcurrencyDebug 1"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-com.apple.CoreData.MigrationDebug 1"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "CFNETWORK_DIAGNOSTICS"
value = "3"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54ACC27B21061B3B0020715F"
BuildableName = "baRSS.app"
BlueprintName = "baRSS"
ReferencedContainer = "container:baRSS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -32,7 +32,6 @@ static int32_t const kDefaultFeedRefreshInterval = 30 * 60;
- (void)setSucessfulWithResponse:(NSHTTPURLResponse*)response; - (void)setSucessfulWithResponse:(NSHTTPURLResponse*)response;
// Setter // Setter
- (void)setUrlIfChanged:(NSString*)url; - (void)setUrlIfChanged:(NSString*)url;
- (void)setEtag:(NSString*)etag modified:(NSString*)modified;
- (BOOL)setRefreshAndSchedule:(int32_t)refresh; - (BOOL)setRefreshAndSchedule:(int32_t)refresh;
- (void)scheduleNow:(NSTimeInterval)future; - (void)scheduleNow:(NSTimeInterval)future;
@end @end

View File

@@ -54,7 +54,10 @@
- (void)setSucessfulWithResponse:(NSHTTPURLResponse*)response { - (void)setSucessfulWithResponse:(NSHTTPURLResponse*)response {
self.errorCount = 0; // reset counter self.errorCount = 0; // reset counter
NSDictionary *header = [response allHeaderFields]; 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]; [self scheduleNow:self.refresh];
} }

View File

@@ -70,9 +70,10 @@ static _Atomic(NSUInteger) _queueSize = 0;
+ (NSURLRequest*)newRequest:(FeedMeta*)meta ignoreCache:(BOOL)flag { + (NSURLRequest*)newRequest:(FeedMeta*)meta ignoreCache:(BOOL)flag {
NSMutableURLRequest *req = [self newRequestURL:meta.url]; NSMutableURLRequest *req = [self newRequestURL:meta.url];
if (!flag) { 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) if (meta.etag.length > 0)
[req setValue:meta.etag forHTTPHeaderField:@"If-None-Match"]; // ETag [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"]; [req setValue:meta.modified forHTTPHeaderField:@"If-Modified-Since"];
} }
if (!_requestsAreUrgent) // any request that is not forced, is a background update if (!_requestsAreUrgent) // any request that is not forced, is a background update

View File

@@ -70,7 +70,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>11387</string> <string>11491</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.news</string> <string>public.app-category.news</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@@ -83,4 +83,6 @@
}]; }];
} }
// x-apple.systempreferences:com.apple.preferences.users?startupItemsPref
@end @end