implementing an http proxy in java
843790Feb 21 2009 — edited Feb 24 2009Hello,
I am finishing a free http proxy software.
When coding HTTP/1.0 behavior here is my algo
1 - open socket
2 - send request
3 - read response and send back to client
4 - when response over close connection
When content-lenght header is provided, then I know when end of response is reached and when to close the socket.
Question is:
Remote server does not always provide a content-length header (ex google.com servers don't). Why not ?
If server does not provide it, how should I know response is finished ?
W3C HTTP spec says that if no content-length header is provided , end of response is known as connection being closed.
But in java, there is no way to know that socket has been closed by remote server, right ?
My current algo tries again and again for X times to read on the socket when X is reached it decides that response is over. Can't I find a better algo ??
thanks!!!