Skip to content

Commit

Permalink
option to ignore Cache-Control and Pragma
Browse files Browse the repository at this point in the history
  • Loading branch information
evermeer committed Nov 12, 2016
1 parent 8c88d87 commit 008b9c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
5 changes: 3 additions & 2 deletions EVURLCache.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |s|
#

s.name = "EVURLCache"
s.version = "3.0.2"
s.version = "3.2.0"
s.summary = "NSURLCache subclass for handeling all web requests that use NSURLRequest"
s.description = "This is a NSURLCache subclass for handeling all web requests that use NSURLRequest. (This includes UIWebView)"
s.homepage = "https://github.com/evermeer/EVURLCache"
Expand All @@ -34,7 +34,8 @@ s.license = { :type => "MIT", :file => "LICENSE" }
# profile URL.
#

s.authors = {"evermeer" => "[email protected]"}
s.author = "evermeer"
s.authors = { 'Edwin Vermeer' => '[email protected]' }
s.social_media_url = "http://twitter.com/evermeer"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
7 changes: 1 addition & 6 deletions EVURLCache/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>evict.nl</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>game.zorropk.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
Expand Down
20 changes: 11 additions & 9 deletions EVURLCache/Pod/EVURLCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ open class EVURLCache: URLCache {
open static var _cacheDirectory: String!
open static var _preCacheDirectory: String!
open static var RECREATE_CACHE_RESPONSE = true // There is a difrence between unarchiving and recreating. I have to find out what.
open static var IGNORE_CACHE_CONTROL = false // By default respect the cache control (and pragma) what is returned by the server
fileprivate static var _filter = { _ in return true } as ((_ request: URLRequest) -> Bool)

// Activate EVURLCache
Expand Down Expand Up @@ -156,20 +157,21 @@ open class EVURLCache: URLCache {
}

// check if caching is allowed according to the response Cache-Control or Pragma header
if let httpResponse = cachedResponse.response as? HTTPURLResponse {
if let cacheControl = httpResponse.allHeaderFields["Cache-Control"] as? String {
if cacheControl.lowercased().contains("no-cache") || cacheControl.lowercased().contains("no-store") {
shouldSkipCache = "response cache control"
if !EVURLCache.IGNORE_CACHE_CONTROL {
if let httpResponse = cachedResponse.response as? HTTPURLResponse {
if let cacheControl = httpResponse.allHeaderFields["Cache-Control"] as? String {
if cacheControl.lowercased().contains("no-cache") || cacheControl.lowercased().contains("no-store") {
shouldSkipCache = "response cache control"
}
}
}

if let cacheControl = httpResponse.allHeaderFields["Pragma"] as? String {
if cacheControl.lowercased().contains("no-cache") {
shouldSkipCache = "response pragma"
if let cacheControl = httpResponse.allHeaderFields["Pragma"] as? String {
if cacheControl.lowercased().contains("no-cache") {
shouldSkipCache = "response pragma"
}
}
}
}

if shouldSkipCache != nil {
// If the file is in the PreCache folder, then we do want to save a copy in case we are without internet connection
let storagePath = EVURLCache.storagePathForRequest(request, rootPath: EVURLCache._preCacheDirectory) ?? ""
Expand Down

0 comments on commit 008b9c9

Please sign in to comment.