问题描述
我正在尝试开发一个chrome扩展,它会在某些请求中设置host标头。但是文档与是否可以修改主机标头是矛盾的。
I am trying to develop a chrome extension that would set the "host" header on certain requests. But the documentation is contradicting as to if the "host" header can be modified or not.
这两个问题都表明a)它不可能和b)不可能
Both of these issues indicate that a) it should not be possible and b) it is impossiblehttps://code.google.com/p/chromium/issues/detail?id=154900https://code.google.com/p/chromium/issues/detail?id=158073
然而,图库中的多个扩展名表示他们会修改主机标题。
,例如
Yet multiple extensions in the gallery state they do modify the "host" header.e.g.https://chrome.google.com/webstore/detail/header-hacker/phnffahgegfkcobeaapbenpmdnkifigc?hl=enhttps://chrome.google.com/webstore/detail/change-http-request-heade/ppmibgfeefcglejjlpeihfdimbkfbbnm
是否有可能修改windows版chrome中的host标题,如果是这样的话?
Is it possible to modify the "host" header in the windows version of chrome, and if so how?
背景:我希望能够测试每个主机上的负载均衡Web实例直接通过IP地址。 hosts文件对于大量主机来说很麻烦。目前我使用curl传递修改后的主机标题,但我确实需要浏览器中的解决方案并可供其他人使用。
Background: I want to be able to test load balanced web instances hitting each host directly via ip address. The "hosts" file is to cumbersome for a large number of hosts. At the moment I use curl to pass the modified "host" header, but I really need the solution in the browser and available for others.
推荐答案
看起来你应该没有这么做的困难。使用onBeforeRequest
It looks like you shouldn't have difficulty doing this. Use onBeforeRequest
因为这是在任何连接之前触发的到服务器,您应该能够修改主机头然后。确保清单中有requestHeaders权限,否则您根本看不到请求标题。
Since this is triggered before any connection to the server is made, you should be able to modify the host header then [edit: if host header is not available, then use a redirect]. Make sure you have the "requestHeaders" permission in the manifest or else you won't see the request headers at all.
这篇关于我该如何修改主机头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!