设置 HTTP 代理以插入标头

发布于 2024-07-05 17:34:42 字数 135 浏览 14 评论 0原文

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

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

染年凉城似染瑾 2024-07-12 17:34:43

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

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.

ゝ偶尔ゞ 2024-07-12 17:34:43

我没有使用代理,而是使用 Firefox 插件 "修改标头” 插入标头(在我的例子中,使用单点登录伪造登录,以便我可以以不同的人身份进行测试)。

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).

愚人国度 2024-07-12 17:34:43

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

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").

安静被遗忘 2024-07-12 17:34:43

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

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

看轻我的陪伴 2024-07-12 17:34:43

我会尝试tinyproxy。 事实上,最好的办法就是在那里嵌入一种脚本语言......听起来对于 Lua,特别是在看到它对 mysqlproxy 的效果之后

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

冰雪梦之恋 2024-07-12 17:34:43

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

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

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

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

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

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.

To add a custom header, just add a line in the OnBeforeRequest function:

oSession.oRequest.headers.Add("MyHeader", "MyValue");
萌吟 2024-07-12 17:34:43

我在开发环境中执行类似的操作,将端口 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>

请参阅 LocationMatchRequestHeader 文档。

这会将标头 myheader: myvalue 添加到发送至应用程序服务器的请求。

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:

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 LocationMatch and RequestHeader documentation.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文