Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324679 - Filters and static content don't mix
Summary: Filters and static content don't mix
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: 8.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 7.1.x   Edit
Assignee: Greg Wilkins CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-07 13:59 EDT by David Jencks CLA
Modified: 2010-09-10 03:19 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.