chore(fetcher): set Origin header and add back proxy headers

This commit is contained in:
WebStreamr 2025-05-23 10:52:49 +00:00
parent 8e791bbe24
commit b313c4eb8d
No known key found for this signature in database
2 changed files with 26 additions and 1 deletions

View file

@ -26,8 +26,13 @@ describe('fetch', () => {
'https://some-url.test/',
{
headers: {
'Forwarded': 'for=127.0.0.1',
'Origin': 'https://some-url.test',
'User-Agent': expect.not.stringMatching(/jest/),
'Referer': 'https://some-url.test',
'X-Forwarded-For': '127.0.0.1',
'X-Forwarded-Proto': 'https',
'X-Real-IP': '127.0.0.1',
},
responseType: 'text',
timeout: 15000,
@ -52,8 +57,13 @@ describe('fetch', () => {
},
{
headers: {
'Forwarded': 'for=127.0.0.1',
'Origin': 'https://some-url.test',
'User-Agent': expect.not.stringMatching(/jest/),
'Referer': 'https://some-url.test',
'X-Forwarded-For': '127.0.0.1',
'X-Forwarded-Proto': 'https',
'X-Real-IP': '127.0.0.1',
},
responseType: 'text',
timeout: 15000,
@ -67,8 +77,13 @@ describe('fetch', () => {
},
{
headers: {
'Forwarded': 'for=127.0.0.1',
'Origin': 'https://some-url.test',
'User-Agent': 'jest',
'Referer': 'https://some-url.test',
'X-Forwarded-For': '127.0.0.1',
'X-Forwarded-Proto': 'https',
'X-Real-IP': '127.0.0.1',
},
responseType: 'text',
timeout: 15000,
@ -90,8 +105,13 @@ describe('fetch', () => {
'https://some-url.test/',
{
headers: {
'Forwarded': 'for=127.0.0.1',
'Origin': 'https://some-url.test',
'User-Agent': expect.not.stringMatching(/jest/),
'Referer': 'https://some-url.test',
'X-Forwarded-For': '127.0.0.1',
'X-Forwarded-Proto': 'https',
'X-Real-IP': '127.0.0.1',
},
responseType: 'text',
timeout: 15000,

View file

@ -40,8 +40,13 @@ export class Fetcher {
timeout: 15000,
...config,
headers: {
'User-Agent': this.createUserAgentForIp(ctx.ip),
'Forwarded': `for=${ctx.ip}`,
'Origin': `${url.origin}`,
'Referer': `${url.origin}`,
'User-Agent': this.createUserAgentForIp(ctx.ip),
'X-Forwarded-For': ctx.ip,
'X-Forwarded-Proto': url.protocol.slice(0, -1),
'X-Real-IP': ctx.ip,
...config?.headers,
},
};