mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Move Cache-Control responsibility to LocalAccountRefresher.
This commit is contained in:
@@ -36,7 +36,7 @@ final class LocalAccountRefresher {
|
||||
|
||||
public func refreshFeeds(_ feeds: Set<WebFeed>, completion: (() -> Void)? = nil) {
|
||||
|
||||
let filteredFeeds = feeds.filter { !Self.feedIsDisallowed($0) }
|
||||
let filteredFeeds = feeds.filter { !feedShouldBeSkipped($0) }
|
||||
|
||||
guard !filteredFeeds.isEmpty else {
|
||||
Task { @MainActor in
|
||||
@@ -177,6 +177,16 @@ private extension LocalAccountRefresher {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func feedShouldBeSkipped(_ feed: WebFeed) -> Bool {
|
||||
|
||||
if let cacheControlInfo = feed.cacheControlInfo, !cacheControlInfo.isExpired {
|
||||
os_log(.debug, "Dropping request for Cache-Control reasons: \(feed.url)")
|
||||
return true
|
||||
}
|
||||
|
||||
return Self.feedIsDisallowed(feed)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Utility
|
||||
|
||||
@@ -32,7 +32,6 @@ public protocol DownloadSessionDelegate {
|
||||
private let delegate: DownloadSessionDelegate
|
||||
private var redirectCache = [URL: URL]()
|
||||
private var queue = [URL]()
|
||||
private var cacheControlResponses = [URL: CacheControlInfo]()
|
||||
|
||||
// 429 Too Many Requests responses
|
||||
private var retryAfterMessages = [String: HTTPResponse429]()
|
||||
@@ -152,15 +151,6 @@ extension DownloadSession: URLSessionDataDelegate {
|
||||
return
|
||||
}
|
||||
|
||||
if let httpURLResponse = response as? HTTPURLResponse, let cacheControlInfo = CacheControlInfo(urlResponse: httpURLResponse) {
|
||||
if let url = taskInfo?.url {
|
||||
cacheControlResponses[url] = cacheControlInfo
|
||||
if let actualURL = response.url, actualURL != url {
|
||||
cacheControlResponses[actualURL] = cacheControlInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addDataTaskFromQueueIfNecessary()
|
||||
completionHandler(.allow)
|
||||
}
|
||||
@@ -201,10 +191,6 @@ private extension DownloadSession {
|
||||
os_log(.debug, "Dropping request for previous 400-499: \(urlToUse)")
|
||||
return
|
||||
}
|
||||
if requestShouldBeDroppedDueToCacheControl(urlToUse) {
|
||||
os_log(.debug, "Dropping request for Cache-Control reasons: \(urlToUse)")
|
||||
return
|
||||
}
|
||||
|
||||
let urlRequest: URLRequest = {
|
||||
var request = URLRequest(url: urlToUse)
|
||||
@@ -398,17 +384,6 @@ private extension DownloadSession {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// MARK: - Cache-Control responses
|
||||
|
||||
func requestShouldBeDroppedDueToCacheControl(_ url: URL) -> Bool {
|
||||
|
||||
guard let cacheControlInfo = cacheControlResponses[url] else {
|
||||
return false
|
||||
}
|
||||
|
||||
return cacheControlInfo.dateExpired > Date()
|
||||
}
|
||||
}
|
||||
|
||||
extension URLSessionTask {
|
||||
|
||||
Reference in New Issue
Block a user