apify / proxy-chain

Node.js implementation of a proxy server (think Squid) with support for SSL, authentication and upstream proxy chaining.
https://www.npmjs.com/package/proxy-chain
Apache License 2.0
804 stars 138 forks source link

how can i get origin headers of http request #500

Closed RoryXiang closed 1 year ago

RoryXiang commented 1 year ago

my code is :

async function listenReq(page, url) { await page.setRequestInterception(true); // 允许截获请求 page.on('request', async req => { const urlInfo = URL.parse(url) if (req.url() && req.url().includes(urlInfo.hostname)) { const headers = req.headers(); headers['usemagic'] = '1'; await req.continue({ headers: headers }); }else { await req.continue(); } });

}

const server = new ProxyChain.Server({ port: config.proxyPort, verboss: false, prepareRequestFunction: async ({ request }) => { try { let proxyUrl; console.log("--------", JSON.stringify(request.headers)) if ([]) { console.log(1111) proxyUrl = undefined // 不使用代理 undefined } else { proxyUrl = await getProxy() } return ({ upstreamProxyUrl: proxyUrl }); } catch (e) { console.log("proxy error", e) }

and log is : -------- {"host":"ip.900cha.com:443","proxy-connection":"keep-alive","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"}

it seem not origin request headers, i had add property of "usemagic" to headers, but logout without "usemagic" can anyone give me some sug?

jancurn commented 1 year ago

For HTTPS/TLS sites, you can't, because all communication is encrypted. You only see hostname or port at the proxy.