From ad51fd4fbfa32c8f8149e309e05b30b1ffb6db21 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 16 Mar 2026 16:54:27 -0700 Subject: [PATCH 1/2] Add canResume function that takes min and max limits. --- Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift b/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift index a8453e899..6fd52be96 100644 --- a/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift +++ b/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift @@ -22,6 +22,16 @@ nonisolated public struct CacheControlInfo: Codable, Equatable { Date() >= resumeDate } + /// canResume with a clamped maxAge — the actual maxAge + /// is clamped to [minMaxAge, maxMaxAge]. We do this because + /// sites tend to misconfigure their max age — we’ve seen + /// feeds that make this as long as one year, which is + /// clearly not intentional. + public func canResume(minMaxAge: TimeInterval, maxMaxAge: TimeInterval) -> Bool { + let clampedMaxAge = max(minMaxAge, min(maxMaxAge, maxAge)) + return Date() >= dateCreated + clampedMaxAge + } + public init(dateCreated: Date, maxAge: TimeInterval) { self.dateCreated = dateCreated self.maxAge = maxAge From 280bbbf5f585a0eb218bda05560be4eeed2e6dea Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 16 Mar 2026 17:20:59 -0700 Subject: [PATCH 2/2] Respect cache-control, but use min 30 minutes and max 5 hours (since sites often have this misconfigured, often wildly). --- .../LocalAccount/LocalAccountRefresher.swift | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift index fb04907d8..8fdb4f960 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift @@ -156,6 +156,7 @@ import os } if let cacheControlInfo = CacheControlInfo(urlResponse: httpResponse) { + Self.logger.debug("LocalAccountRefresher: setting cacheControlInfo maxAge: \(cacheControlInfo.maxAge) url: \(url.absoluteString)") feed.cacheControlInfo = cacheControlInfo } @@ -281,18 +282,26 @@ private extension LocalAccountRefresher { return false } + static let cacheControlMinMaxAge: TimeInterval = 30 * 60 // 30 minutes + static let cacheControlMaxMaxAge: TimeInterval = 5 * 60 * 60 // 5 hours + static func feedShouldBeSkippedForCacheControlReasons(_ feed: Feed) -> Bool { - // We support Cache-Control only for openrss.org. The rest of the feed-providing - // universe hasn’t dealt with Cache-Control, and we routinely see days-long - // max-ages for even fast-moving feeds. - // - // However, openrss.org does make sure their Cache-Control headers are - // intentional, and we should honor those. + guard let cacheControlInfo = feed.cacheControlInfo, !cacheControlInfo.canResume else { + return false + } + + // openrss.org gets unclamped Cache-Control — they configure it correctly. if SpecialCase.urlStringContainSpecialCase(feed.url, [SpecialCase.openRSSOrgHostName]) { - if let cacheControlInfo = feed.cacheControlInfo, !cacheControlInfo.canResume { - Self.logger.info("LocalAccountRefresher: Dropping request for special case Cache-Control reasons: \(feed.url)") - return true - } + Self.logger.info("LocalAccountRefresher: Dropping request for Cache-Control reasons (openrss.org): \(feed.url)") + return true + } + + // All other feeds: honor Cache-Control with clamped max-age + // (min 30 minutes, max 5 hours) because many sites misconfigure it. + // We’ve seen max-age as long as one year (for a feed that updates frequently). + if !cacheControlInfo.canResume(minMaxAge: cacheControlMinMaxAge, maxMaxAge: cacheControlMaxMaxAge) { + Self.logger.info("LocalAccountRefresher: Dropping request for Cache-Control reasons: \(feed.url)") + return true } return false