From de8e0bdd94f6402edbd60c14b6e3bff22643c283 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Fri, 18 Jul 2025 09:23:31 +0000 Subject: [PATCH] fix: do not use cache and proxy headers for health requests --- src/index.ts | 2 +- src/utils/Fetcher.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index eb3b195..11dcb0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -85,7 +85,7 @@ addon.get('/health', async (req: Request, res: Response) => { const ctx = contextFromRequest(req); try { - const ip = await fetcher.text(ctx, new URL('https://api.ipify.org')); + const ip = await fetcher.text(ctx, new URL('https://api.ipify.org'), { noCache: true, noProxyHeaders: true }); res.json({ status: 'ok', ip }); } catch (error) { diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 76bef0d..034a709 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -44,7 +44,9 @@ interface FlareSolverrResult { export type CustomRequestInit = RequestInit & { timeoutsCountThrow?: number; + noCache?: boolean; noFlareSolverr?: boolean; + noProxyHeaders?: boolean; queueLimit?: number; queueTimeout?: number; timeout?: number; @@ -87,6 +89,7 @@ export class Fetcher { private getInit(ctx: Context, url: URL, init?: CustomRequestInit): CustomRequestInit { const cookieString = this.cookieJar.getCookieStringSync(url.href); + const noProxyHeaders = init?.noProxyHeaders ?? false; return { ...init, @@ -96,7 +99,7 @@ export class Fetcher { 'Priority': 'u=0', 'User-Agent': this.hostUserAgentMap.get(url.host) ?? 'node', ...(cookieString && { Cookie: cookieString }), - ...(ctx.ip && { + ...(ctx.ip && !noProxyHeaders && { 'Forwarded': `for=${ctx.ip}`, 'X-Forwarded-For': ctx.ip, 'X-Forwarded-Proto': url.protocol.slice(0, -1), @@ -223,7 +226,8 @@ export class Fetcher { const cacheKey = this.determineCacheKey(url, init); let httpCacheItem = this.cacheGet(cacheKey); - if (httpCacheItem) { + const noCache = init?.noCache ?? false; + if (httpCacheItem && !noCache) { this.logger.info(`Cached fetch ${request.method} ${url}`, ctx); return this.handleHttpCacheItem(ctx, httpCacheItem, url, init); }