我该如何修改主机头 [英] How can i modify the host header

查看:200
本文介绍了我该如何修改主机头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个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)不可能
https://code.google.com/p/chromium/issues/detail?id=154900
https://code.google.com/p/chromium/issues/detail ?id = 158073

Both of these issues indicate that a) it should not be possible and b) it is impossible https://code.google.com/p/chromium/issues/detail?id=154900 https://code.google.com/p/chromium/issues/detail?id=158073

然而,图库中的多个扩展名表示他们会修改主机标题。
,例如
https://chrome.google.com/webstore / detail / header-hacker / phnffahgegfkcobeaapbenpmdnkifigc?hl = en
https://chrome.google.com/webstore/detail/change-http-request-heade/ppmibgfeefcglejjlpeihfdimbkfbbnm

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=en https://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


onBeforeRequest:请求即将发生时触发。此事件在进行任何TCP连接之前发送,可用于取消或重定向请求。

onBeforeRequest: Fires when a request is about to occur. This event is sent before any TCP connection is made and can be used to cancel or redirect requests.

因为这是在任何连接之前触发的到服务器,您应该能够修改主机头然后。确保清单中有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.

这篇关于我该如何修改主机头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆