I have 2 different servlets, both are handling POST calls, both stream a file as the result. One always ends up with a Content-Length header, the other never does. They both use javax.servlet.http.HttpServletResponse.
Both set "Content-Type" = "application/octet-stream";
I haven't been able to figure out what I could be doing to cause this difference.
The only real difference I see in the processing is that the size of the file of the one that does NOT get a Content-Length is generally multiple MB, and the other is usually just a few KB.
Just for the heck of it I did try using the response.AddHeader("thing", size), and noticed that that header never showed up for either servlet.
Note that I'm receiving the file on an OS/X machine, and using the [NSHTTPURLResponse allHeaders] to see the response headers.
Here is some HEAVILY trimmed down code. Basically only kept anything that refd the response:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/octet-stream");
resp.setBufferSize(256 * 1024);
OutputStream rout = resp.getOutputStream();
// lots of work getting the stream
// Also left out all the exception handling and error checking
IOUtils.copy(datafile, rout);
rout.close();
resp.addIntHeader("OnDeck-Test", 555);
}