Skip x-ratelimit headers when served from cache

This commit is contained in:
Zed 2026-06-20 12:55:32 +02:00
commit 5a2df5df2e

View file

@ -8,6 +8,7 @@ const
rlRemaining = "x-rate-limit-remaining" rlRemaining = "x-rate-limit-remaining"
rlReset = "x-rate-limit-reset" rlReset = "x-rate-limit-reset"
rlLimit = "x-rate-limit-limit" rlLimit = "x-rate-limit-limit"
npCache = "x-np-cache"
errorsToSkip = {null, doesntExist, tweetNotFound, timeout, unauthorized, badRequest} errorsToSkip = {null, doesntExist, tweetNotFound, timeout, unauthorized, badRequest}
var var
@ -139,7 +140,8 @@ template fetchImpl(result, fetchBody) {.dirty.} =
echo "[sessions] transient 404 (empty body), retrying: ", url.path, ", session: ", session.pretty echo "[sessions] transient 404 (empty body), retrying: ", url.path, ", session: ", session.pretty
raise rateLimitError() raise rateLimitError()
if resp.headers.hasKey(rlRemaining): let cacheStatus = resp.headers.getOrDefault(npCache)
if cacheStatus notin ["HIT", "STALE"] and resp.headers.hasKey(rlRemaining):
let let
remaining = parseInt(resp.headers[rlRemaining]) remaining = parseInt(resp.headers[rlRemaining])
reset = parseInt(resp.headers[rlReset]) reset = parseInt(resp.headers[rlReset])