chore(fetcher): complete proxy headers

This commit is contained in:
WebStreamr 2025-09-23 08:50:56 +00:00
parent 7e771c2644
commit 0a0bedacb4
No known key found for this signature in database
2 changed files with 7 additions and 3 deletions

View file

@ -31,10 +31,11 @@ describe('fetch', () => {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en',
'Authorization': 'Basic dXNlcjpwYXNz',
'Forwarded': 'for=0.0.0.0',
'Forwarded': 'by=unknown;for=0.0.0.0;host=some-url.test;proto=https',
'Priority': 'u=0',
'User-Agent': 'node',
'X-Forwarded-For': '0.0.0.0',
'X-Forwarded-Host': 'some-url.test',
'X-Forwarded-Proto': 'https',
'X-Real-IP': '0.0.0.0',
});

View file

@ -105,6 +105,8 @@ export class Fetcher {
const cookieString = this.cookieJar.getCookieStringSync(url.href);
const noProxyHeaders = init?.noProxyHeaders ?? false;
const forwardedProto = url.protocol.slice(0, -1);
return {
...init,
headers: {
@ -115,9 +117,10 @@ export class Fetcher {
'User-Agent': this.hostUserAgentMap.get(url.host) ?? 'node',
...(cookieString && { Cookie: cookieString }),
...(ctx.ip && !noProxyHeaders && {
'Forwarded': `for=${ctx.ip}`,
'Forwarded': `by=unknown;for=${ctx.ip};host=${url.host};proto=${forwardedProto}`,
'X-Forwarded-For': ctx.ip,
'X-Forwarded-Proto': url.protocol.slice(0, -1),
'X-Forwarded-Host': url.host,
'X-Forwarded-Proto': forwardedProto,
'X-Real-IP': ctx.ip,
}),
...init?.headers,