views:

50

answers:

2

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

+2  A: 

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:

  1. It requires driver development (with all the consequences)
  2. 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.

valdo
@valdo: I just want to add the same header to all HTTP packets. How can this affect the TCP stream? Also, HTTP protocol is a stateless protocol and I don't see that the idea is wrong. The new header will be processed by the server (I will patch my proxy to support it).
Khaled
There's no such a thing as HTTP packets. What you see in the sniffer are IP protocol packets, which carry pieces of data transmitted by TCP, and the data itself is a part of the HTTP protocol.
valdo
Note that its not just a question of adding headers to the stream - a single HTTP stream can contain multiple requests/responses
symcbean
A: 

It's all going to go horribly wrong until you learn the difference between packets, requests/responses and streams.

Write an HTTP proxy instead.

symcbean
I know that requests are those packets which are originated by my host. Responses are the packets coming from the remote host. Do you mean this or something different? Writting an HTTP proxy is not a trivial task!
Khaled
"I know that requests are those packets which..." - no you don't. Writing an HTTP proxy is a lot simpler than creating a HTTP header injector MITM
symcbean