From 375addb589e911d8bb224245313d741d981390db Mon Sep 17 00:00:00 2001 From: fengkx Date: Tue, 9 Mar 2021 15:24:06 +0800 Subject: [PATCH] fix: default http_cache to false --- source/config.ts | 4 +--- source/utils/fetch.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/config.ts b/source/config.ts index 9d391cbbede..a1a9f150e2e 100644 --- a/source/config.ts +++ b/source/config.ts @@ -24,9 +24,7 @@ export const config: Config = { strict_ttl: process.env.RSSBOT_STRICT_TTL !== '0' && process.env.RSSBOT_STRICT_TTL !== 'false', - http_cache: - process.env.RSSBOT_HTTP_CACHE !== '0' && - process.env.RSSBOT_HTTP_CACHE !== 'fasle', + http_cache: !!process.env.RSSBOT_HTTP_CACHE || false, notify_error_count: parseInt(process.env.NOTIFY_ERR_COUNT) || 5, view_all: !!process.env.RSSBOT_VIEW_ALL || false, UA: diff --git a/source/utils/fetch.ts b/source/utils/fetch.ts index 2291c879cad..103e96b7796 100644 --- a/source/utils/fetch.ts +++ b/source/utils/fetch.ts @@ -80,14 +80,16 @@ async function fetch(feedModal: Feed): Promise> { const feedUrl = feedModal.url; try { logger.debug(`fetching ${feedUrl}`); - const res = await got - .get(encodeURI(feedUrl), { - headers: { - 'If-None-Match': feedModal.etag_header, - 'If-Modified-Since': feedModal.last_modified_header - } - }) - .on('request', gotBugWorkaround); + const request = got.get(encodeURI(feedUrl), { + headers: { + 'If-None-Match': feedModal.etag_header, + 'If-Modified-Since': feedModal.last_modified_header + } + }); + if (config.http_cache) { + request.on('request', gotBugWorkaround); + } + const res = await request; if (res.statusCode === 304) { const updatedFeedModal: Partial & { feed_id: number } = { feed_id: feedModal.feed_id,