Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

implementing an http proxy in java

843790Feb 21 2009 — edited Feb 24 2009
Hello,
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!!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2009
Added on Feb 21 2009
11 comments
2,718 views