apache 设置 HTTP 代理以插入标头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/154441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:47:26  来源:igfitidea点击:

Set up an HTTP proxy to insert a header

apacheproxyhttp-headersproxypass

提问by Logan

I need to test some HTTP interaction with a client I'd rather not modify. What I need to test is the behavior of the server when the client's requests include a certain, static header.

我需要测试一些与我不想修改的客户端的 HTTP 交互。我需要测试的是当客户端的请求包含某个静态标头时服务器的行为。

I'm thinking the easiest way to run this test is to set up an HTTP proxy that inserts the header on every request. What would be the simplest way to set this up?

我认为运行此测试的最简单方法是设置一个 HTTP 代理,在每个请求中插入标头。设置它的最简单方法是什么?

回答by Peter Hilton

I do something like this in my development environment by configuring Apache on port 80 as a proxy for my application server on port 8080, with the following Apache config:

我通过在端口 80 上将 Apache 配置为端口 8080 上的应用程序服务器的代理,使用以下 Apache 配置在我的开发环境中执行类似操作:

NameVirtualHost *
<VirtualHost *>
   <Proxy http://127.0.0.1:8080/*>
      Allow from all
   </Proxy>
   <LocationMatch "/myapp">
      ProxyPass http://127.0.0.1:8080/myapp
      ProxyPassReverse http://127.0.0.1:8080/myapp
      Header add myheader "myvalue"
      RequestHeader set myheader "myvalue"   
   </LocationMatch>
</VirtualHost>

See LocationMatchand RequestHeaderdocumentation.

请参阅LocationMatchRequestHeader文档。

This adds the header myheader: myvalueto requests going to the application server.

这将标题myheader: myvalue 添加到前往应用程序服务器的请求中。

回答by Nico

You can also install Fiddler (http://www.fiddler2.com/fiddler2/) which is very easy to install (easier than Apache for example).

您还可以安装 Fiddler ( http://www.fiddler2.com/fiddler2/),它非常易于安装(例如比 Apache 更容易)。

After launching it, it will register itself as system proxy. Then open the "Rules" menu, and choose "Customize Rules..." to open a JScript file which allow you to customize requests.

启动后,它将自己注册为系统代理。然后打开“规则”菜单,选择“自定义规则...”打开一个 JScript 文件,允许您自定义请求。

To add a custom header, just add a line in the OnBeforeRequestfunction:

要添加自定义标题,只需在OnBeforeRequest函数中添加一行:

oSession.oRequest.headers.Add("MyHeader", "MyValue");

回答by Javier

i'd try tinyproxy. in fact, the vey best would be to embedd a scripting language there... sounds like a perfect job for Lua, especially after seeing how well it worked for mysqlproxy

我会尝试tinyproxy。事实上,最好的办法是在那里嵌入一种脚本语言......听起来对Lua来说是一个完美的工作,尤其是在看到它对mysqlproxy 的效果如何之后

回答by Kevin Hakanson

I have had co-workers that have used Burp("an interactive HTTP/S proxy server for attacking and testing web applications") for this. You also may be able to use Fiddler("a HTTP Debugging Proxy").

我有同事为此使用过Burp(“用于攻击和测试 Web 应用程序的交互式 HTTP/S 代理服务器”)。您也可以使用Fiddler(“HTTP 调试代理”)。

回答by Eduardo

Use http://www.proxomitron.infoand set up the header you want, etc.

使用http://www.proxomitron.info并设置您想要的标题等。

回答by Paul Tomblin

Rather than using a proxy, I'm using the Firefox plugin "Modify Headers"to insert headers (in my case, to fake a login using the Single Sign On so I can test as different people).

我没有使用代理,而是使用 Firefox 插件“修改标题”来插入标题(在我的情况下,使用单点登录伪造登录,以便我可以作为不同的人进行测试)。

回答by John Bowers

If you have ruby on your system, how about a small Ruby Proxy using Sinatra (make sure to install the Sinatra Gem). This should be easier than setting up apache. The code can be found here.

如果您的系统上有 ruby​​,那么使用 Sinatra 的小型 Rub​​y 代理如何(确保安装 Sinatra Gem)。这应该比设置 apache 更容易。代码可以在这里找到