forked from Archives/Athou_commafeed
correctly handle 0 as a Retry-Header value (#1671)
This commit is contained in:
@@ -9,7 +9,6 @@ import java.time.InstantSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -111,7 +110,7 @@ public class HttpGetter {
|
||||
}
|
||||
|
||||
int code = response.getCode();
|
||||
if (Set.of(HttpStatus.SC_TOO_MANY_REQUESTS, HttpStatus.SC_SERVICE_UNAVAILABLE).contains(code) && response.getRetryAfter() != null) {
|
||||
if (code == HttpStatus.SC_TOO_MANY_REQUESTS || code == HttpStatus.SC_SERVICE_UNAVAILABLE && response.getRetryAfter() != null) {
|
||||
throw new TooManyRequestsException(response.getRetryAfter());
|
||||
}
|
||||
|
||||
|
||||
@@ -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