I make a web proxy in c++. It works great by it always stay some little bug. For exemple: When I load the msn home page, there sometime some picture seems broken (X). I can connect to https site but, in Facebook, i cant update my statue. All the other thing work but not this one. The little chat on the left in gmail dont work. Little think like that! Youtube work great! SOme ajax web site work great but, not all!
Each time the port receive a connection
Create a new thread
This is the execution of the new thread:
Receive http request from Browser
Parse the header and connect to server
Send the http request to server
Loop while a connection is close
Manage who wants to talk (Server or Browser)
Transfert the data from who wants to talk to the other
GET / HTTP/1.1
and if the header use the CONNECT methode, I create the connection to the server from the specified port and adresse: CONNECT www.app.com:443 HTTP/1.1 and I return a "HTTP/1.0 200 Connection established\r\n\r\n" to the browser.
The next step, I think, is to open each header send by the browser to see if the information is corect like i do for the first one. If someone have an other idea. plz. talk!
Usually, the source of this problem is the expectations of the browser when it deals with a proxy, as opposed to situations where a proxy is not involved.
Without a proxy, the browser knows to make a new connection when it needs data from a different host. When it knows that it is dealing with a proxy, however, the browser will rely on the proxy to notice when a connection to a different host is needed.
In other words, without a proxy the browser will make a first HTTP request for data from a first host via a first connection to the host. Then, when data from a second host is needed, the browser will make a second, different connection to the second host, and send a second HTTP request to the second host over the second connection.
On the other hand, when it knows that it is dealing with a proxy, the browser will make a first connection to the proxy and send a first HTTP request for data from a first host. But when it needs data from a second host, the browser will re-use the same first connection to the proxy, and will send a second HTTP request for the second host using the same first connection. The browser relies on the proxy to notice that a new connection is needed for connection to a second host.
Your proxy probably does not expect a switch to a different host. It probably assumes that when the browser asks for data initially, then all data will be requested from the same host, and it thus fails to make a new connection to the second host. Instead, it sends the meaningless second HTTP request to the first host, which naturally is unable to fulfill it -- hence the boxes.
You seem to realize this somewhat, since you are modifying the HTTP/1.1 headers sent to the host so that the headers include the "Connection: Close" header. But you also need to send that header back to the browser, or the browser will not close the connection to the proxy, but rather will try to re-use it.