You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Tennessee Leeuwenburg <t....@bom.gov.au> on 2005/01/06 06:09:37 UTC

Handling HEAD request in servlet

Hi guys,

I have a problem where the default implementation of HttpServlet doesn't 
seem to be handling doHead(request, response) properly. I over-rode the 
method, and found the damndest thing happening. The line 
"response.setContentLength(length)" is just getting completely ignored. 
I can't work it out - it's like the response object is deliberately 
preventing me from setting the content-length. I tried 
setHeader("Content-Length", length) just in case but still no joy.

Help!? Please!
-------------------------------------------------

Here's the code snippet :

                FileInputStream inStream = null;
       
                inStream = new FileInputStream(ncFile);
                int length = (int)ncFile.length();
                response.setStatus(response.SC_PARTIAL_CONTENT); 
                response.setHeader("Accept-Ranges", "bytes");
                response.setContentLength(length);
                response.setHeader("Content-Length-Mimic", 
""+(int)ncFile.length());
                response.setHeader("Impossible", "" + length);
                response.setContentType(contentType);
               
                out.flush();

Here's what I get back via telnet :

HTTP/1.1 206 Partial Content
Date: Thu, 06 Jan 2005 05:07:22 GMT
Server: Apache/2.0.50 (Ubuntu) mod_jk2/2.0.4
Set-Cookie: JSESSIONID=3D6C4C6EBE1AB1672E40C2933243BA3B; Path=/marslet
Accept-Ranges: bytes
Content-Length-Mimic: 36903060
Impossible: 36903060
Content-Type: application/x-netcdf
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org