fix: do not use cache and proxy headers for health requests

This commit is contained in:
WebStreamr 2025-07-18 09:23:31 +00:00
parent 258859462f
commit de8e0bdd94
No known key found for this signature in database
2 changed files with 7 additions and 3 deletions

View file

@ -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) {

View file

@ -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);
}