mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-24 04:57:50 +00:00
correctly handle 0 as a Retry-Header value (#1671)
This commit is contained in:
@@ -4,6 +4,8 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
@@ -29,6 +31,16 @@ public class FeedRefreshIntervalCalculator {
|
||||
return onFetchSuccess(publishedDate, averageEntryInterval);
|
||||
}
|
||||
|
||||
public Instant onTooManyRequests(Instant retryAfter) {
|
||||
Instant defaultRefreshInterval = getDefaultRefreshInterval();
|
||||
|
||||
if (retryAfter == null) {
|
||||
return defaultRefreshInterval;
|
||||
}
|
||||
|
||||
return ObjectUtils.max(retryAfter, defaultRefreshInterval);
|
||||
}
|
||||
|
||||
public Instant onFetchError(int errorCount) {
|
||||
int retriesBeforeDisable = 3;
|
||||
if (errorCount < retriesBeforeDisable || !empiricalInterval) {
|
||||
|
||||
@@ -104,7 +104,7 @@ public class FeedRefreshWorker {
|
||||
|
||||
feed.setErrorCount(feed.getErrorCount() + 1);
|
||||
feed.setMessage("Server indicated that we are sending too many requests");
|
||||
feed.setDisabledUntil(e.getRetryAfter());
|
||||
feed.setDisabledUntil(refreshIntervalCalculator.onTooManyRequests(e.getRetryAfter()));
|
||||
|
||||
return new FeedRefreshWorkerResult(feed, Collections.emptyList());
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user