Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324679

Summary: Filters and static content don't mix
Product: [RT] Jetty Reporter: David Jencks <david.a.jencks>
Component: serverAssignee: Greg Wilkins <gregw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jetty-inbox, mgorovoy
Version: 8.0.0   
Target Milestone: 7.1.x   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description David Jencks CLA 2010-09-07 13:59:34 EDT
The DefaultServlet and the error page code (which I haven't located) both set the content length unconditionally to the length of the static content unless the request is marked as an include.

If there is a filter that writes content before (or, presumably after) the default content the content length is wrong and the client only gets part of the response.

For the default servlet case, commenting out line 942
//                r.setLongContentLength(count);


and around 951
//            if (count != -1)
//            {
//                if (count<Integer.MAX_VALUE)
//                    response.setContentLength((int)count);
//                else
//                    response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(count));
//            }


fixes the problem but this is surely not a desirable solution.
Comment 1 Greg Wilkins CLA 2010-09-08 23:08:25 EDT
this is a dangerous kind of filter to support.  Filters that change the content length really should wrap the response and control the content length header.

But I have added HttpOutput.isWritten() and the default servlet now checks to see if the response has been written before attempting to set the content length.
Comment 2 David Jencks CLA 2010-09-09 22:08:16 EDT
The fix in trunk in rev 2265 works for response.getOuputStream() but not response.getWriter()
Comment 3 Greg Wilkins CLA 2010-09-10 03:19:59 EDT
r2268 added fix to jetty-7 to handle writers. will merge to 8 soon.