puppeteer request.continue can not work with header host overrided

此生再无相见时 提交于 2020-06-27 16:48:08

问题


Tell us about your environment:

  • Puppeteer version: 1.19.0
  • Platform / OS version: Debian 9
  • URLs (if applicable):
  • Node.js version: 8

What is the expected result?

I want override the request's host in header. Such as a request url: http://a.com/x.jpg. The DNS resolver may be parse the host to a slower ip address, but I know ther is a better ip like 1.2.3.4. I want to change the url with the ip addrees and modify the host in request header.

like from curl http://a.com/x.jpg

to curl --header "Host:a.com" http://1.2.3.4/x.jpg

What happens instead?

await page.setRequestInterception(true);

page.on('request', request => {
  const newHeaders = Object.assign({}, request.headers(), {
    Host: 'a.com'
});

request.continue({ headers: newHeaders, url: 'http://1.2.3.4/x.jpg' });

but it doesn't work

来源:https://stackoverflow.com/questions/60539833/puppeteer-request-continue-can-not-work-with-header-host-overrided

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!