Adding HTTP header to all outgoing packets on Windows?
I am developing a Windows application that will live in the system tray. The application can be enabled/disabled by the user.
Whenever the user enables it, it needs to listen/sniff HTTP traffic and add a specific HTTP header on all outgoing packets.
I think it can be done by changing the system or browser settings to be localhost:my_port. However, this method has several disadvantages such as the need to implement a proxy server within my application.
Can you suggest a better way to do it? I just need to add a specific HTTP header on all outgoing HTTP 开发者_如何转开发packets.
I am using visual C++ 6.0
The simplest way of doing this is what you describe: configure your browser to work via proxy, and then implement it, adding/modifying headers as necessary.
Your idea about adding HTTP headers to outgoing "packets" is wrong. Because you forget that HTTP protocol is based on TCP, which is a stream. That is, you should not do any independent processing to individual packets. They must be done in the context of the connection. (Plus obviously you want to do this for HTTP protocol only).
There are actually methods to do this via "sniffing", seemlessly to the browser. This is however very very much harder to implement.
Because:
- It requires driver development (with all the consequences)
- Since in you specific case you can't do this on individual packet basis - it's even more complex.
So that if you do have the option to tell your browser to go straight into your hands, without digging into the OS internals - you should definitely use this possibility.
It's all going to go horribly wrong until you learn the difference between packets, requests/responses and streams.
Write an HTTP proxy instead.
精彩评论