views:

270

answers:

2

Hi all, I am implementing a HTTP caching proxy server in C++.I am done with most part of it but i am stuck at a point.
What i am doing is creating each thread with a socket to handle each time a request from browser comes. I parse the request, check for its availability in cache and if not found forward it to end www server.In both cases i write the response received on the connected socket. Now the problem is until and unless i close the socket, the browser doesn't assumes the transfer to be complete and waits indefinitely.
This way I can't use a socket for more than one connection, in other words I can't support persistent connections.
Any help will be appreciated..

Thanks,

+1  A: 

What headers are you sending back to the client?

You should be including:

Content-Length: ...
Keep-Alive: timeout=..., max=...
Connection: Keep-Alive

In particular, the Content-Length header is essential with persistent connections so that the client knows how much data to read. See section 8.1.2.1 of RFC 2616.

Alternatively, if you want to tell the client to break the connection, send:

Connection: close
Alnitak
A: 

Now the problem is until and unless i close the socket, the browser doesn't assumes the transfer to be complete and waits indefinitely.

Right. HTTP 1.1 uses Keep-Alive by default.

This way I can't use a socket for more than one connection, in other words I can't support persistent connections.

I'm not sure I understand you, because that persistent connection you have IS a persistent connection.

Blank Xavier