Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need some clarification about keep-alives and content-lengths

 
Charles Cayman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, here the concept that gets me puzzled.
1.) I read that Keep-Alives are there to avoid unnecessary re-establishments of connections on web pages that have more than one file (e.g., with graphics, etc.)
2.) In a socket connection, the browser will know that a particular file is ended by counting the Content-Length header sent by the server, so that the browser can request more files.
3.) So, my impression is that, when we produce a file using
PrintWriter out = HttpServletResponse.getWriter();
out.println();...
The servlet postpones the sending of the text through the connection until it knows exactly how long the response is.
4.) So, now my question is: What happens if the HTML file that we're producing is larger than the output/response buffer (usually 8K)? The servlet must send the initial 8K of data, but it still does not know how many will be sent...
If it does not know the total length, then it can't set the Content-Length header...
but if it does not set the Content-Length header, then it can't send the data...

Where am I wrong here??? Thank you in advance
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Content-length is really only essential for resources like zip files, image files and pdf files where special handling is needed and you can figure out the length before sending anything. Browsers obviously can cope with HTML that just keeps on coming. A browser can start requesting images, etc. before the HTML is complete without opening a new connection.
Bill
 
Charles Cayman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clearing that one up!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic