如何在服务器端拦截和修改HTTP响应?
我正在使用一个使用 HTTP 的客户端/服务器应用程序,我的目标是为其添加新功能。我可以通过将自己的代码挂钩到某些特定事件来扩展客户端,但不幸的是服务器不可自定义。客户端和服务器都在Windows环境下。
我当前的问题是,当从服务器接收大量数据时,性能很糟糕:传输数据和处理数据都需要时间。解决方案可能是在服务器端使用应用程序来进行处理并仅发送结果(结果要小得多)。问题是没有内置函数可以在发送服务器响应之前对其进行操作。
我正在考虑监听端口 80 上的所有流量,识别相关的 HTTP 响应并将它们发送到我的应用程序,同时阻止响应(以避免发送客户端无法处理的大量数据)。由于我缺乏很多网络知识,所以在思考如何去做的时候我有点茫然。
我查看了一些低级数据包拦截方法,例如 WinPCap,但似乎需要做很多工作才能完成我需要的工作。此外,我认为不可能使用此 API 阻止或修改响应。
允许由特定请求或响应触发用户脚本的反向代理将是完美的,但我想知道是否没有更简单的方法来执行此拦截/发送到其他地方的工作。
实现这种行为的最简单、最干净的方法是什么?
谢谢!
I am working with a client/server application which uses HTTP, and my goal is to add new features to it. I can extend the client by hooking my own code to some specific events, but unfortunately the server is not customizable. Both client and server are in a Windows environment.
My current problem is that performance is awful when a lot of data are received from the server: it takes time to transmit it and time to process it. The solution could be to have an application on server side to do the processing and send only the result (which is much smaller). The problem is there is not built-in functions to manipulate responses from the server before sending them.
I was thinking to listen to all traffic on port 80, identifying relevant HTTP responses and send them to my application while blocking the response (to avoid sending huge data volume which won't be processed by the client). As I am lacking a lot of network knowledge, I am a bit lost when thinking about how to do it.
I had a look at some low-level packet intercepting methods like WinPCap, but it seems to require a lot of work to do what I need. Moreover I think it is not possible to block or modify responses with this API.
A reverse proxy which allows user scripts to be triggered by specific requests or responses would be perfect, but I am wondering if there is no simpler way to do this interception/send elsewhere work.
What would be the simplest and cleanest method to enable this behavior?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我结束了制作一个简单的反向代理来访问 HTTP 服务器。然后,反向代理从服务器响应中提取相关信息并将其发送到服务器端处理组件,并用客户端用来请求其他组件获取处理结果的 ID 替换从响应中提取的信息。
文章位于 http://www.codeproject.com/KB/web-security/ HTTPReverseProxy.aspx 对于制定反向代理的初稿非常有帮助。
I ended making a simple reverse proxy to access the HTTP server. The reverse proxy then extracts relevant information from the server response and sends it to the server-side processing component, and replaces information extracted from the response by an ID the client uses to request the other component to get the processing results.
The article at http://www.codeproject.com/KB/web-security/HTTPReverseProxy.aspx was very helpful to make the first draft of the reverse proxy.
嗯....选择太多了。
2个想法:
在所有客户端上配置 Http 代理。有一些可以让您操纵两个方向上发生的事情(使用脚本、插件)。
或者
制作一个直通项目,监听端口 80,并将所需的内容转发到端口 8080(原始服务器应用程序运行的位置)
问题是,服务器应用程序运行在什么软件上,
你有什么知识(开发)?
啊。什么是“大数据”?千字节?兆字节?千兆字节?
Hmm.... too much choices.
2 ideas:
configure on all clients a Http Proxy. there are some out there, that let you manipulate what goes through in both directions (with scripts, plugins).
or
make a pass through project, that listens to port 80, and forewards the needed stuff to port 8080 (where your original server app runs)
question is, what software is the server app running at,
and what knowledge (dev) do you have?
ah. and what is "huge data"? kilobyte? megabyte? gigabyte?