tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Duncan McGregor <>
Subject Fwd: If-Range bug in DefaultServlet?
Date Thu, 13 Apr 2006 10:03:39 GMT
I've had no response to my last on this subject.

I know we're all busy, but this one does seem to be pretty  
fundamental, and I did go to a bunch of trouble to write the testcase  
to show the problem ;-)

I'd value some feedback -

	Am I completely wrong in thinking that this is a problem?

	Is there some issue in the way that I reported it?

Duncan McGregor

Begin forwarded message:

> From: Duncan McGregor <>
> Date: 6 April 2006 00:39:57 BDT
> To:
> Subject: If-Range bug in DefaultServlet?
> Hi
> I've been making If-Range requests to Tomcat (5.5.16) and it seems  
> not to be sending back content when the request and current ETags  
> don't match.
> RFC 2616 section 14.27 says
> If the entity tag given in the If-Range header matches the current  
> entity tag for the entity, then the server SHOULD provide the  
> specified sub-range of the entity using a 206 (Partial content)  
> response. If the entity tag does not match, then the server SHOULD  
> return the entire entity using a 200 (OK) response.
> Am I doing something wrong, or is the servlet behaviour not as it  
> SHOULD be?
> Thanks in anticipation
> Duncan McGregor


import junit.framework.TestCase;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;


public class TomcatIfRangeTest extends TestCase {

     protected HttpClient httpClient;
     protected GetMethod getMethod;
     private FTPClient ftpClient;

     public void setUp() throws Exception {
         httpClient = new HttpClient();
         ftpClient = new FTPClient();
         ftpClient.login("user", "user");

     public void testIfRange() throws Exception {
         upload("contents", "delme.txt");
         assertEquals(HttpStatus.SC_OK, get("http://localhost:8080/ 
         String etag = headerValue("ETag");
         assertEquals("contents", responseBody());

                         "If-Range", etag,
                         "Range", "bytes=1-3"
         assertEquals(etag, headerValue("ETag"));
         assertEquals("ont", responseBody());

         upload("new contents", "delme.txt");
                         "If-Range", etag,
                         "Range", "bytes=1-3"
         assertEquals("new contents", responseBody());
	  // FAILS as responseBody is ""

     protected int get(String url, String...headerValues) throws  
HttpException, IOException {
         getMethod = new GetMethod(url);
         for (int i = 0; i < headerValues.length; i += 2) {
             getMethod.addRequestHeader(headerValues[i], headerValues 
[i +1]);
         return httpClient.executeMethod(getMethod);

     protected String responseBody() throws IOException {
         return getMethod.getResponseBodyAsString();

     protected String headerValue(String headerName) {
         Header header = getMethod.getResponseHeader(headerName);
         return header != null ? header.getValue() : null;

     protected void upload(String contents, String path) throws  
Exception {
         ftpClient.put(contents.getBytes(), path);
         Thread.sleep(5000); // TODO - is this a cache timeout?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message