2011/3/8 Mark Thomas <ma...@apache.org>:
> On 07/03/2011 22:52, Konstantin Kolinko wrote:
>> Hi!
>>
>> Regarding the issue we discussed recently about issue 50748,
>> Content-Length header and DefaultServlet.
>>
>> Usually DefaultServlet serves the content using an OutputStream, but
>> if getWriter() was already called, the stream will not be available
>> and ISE will be thrown.
>>
>> There is a workaround implemented for that:
>>
>> In DefaultServlet#serveResource(..):
>>
>>             try {
>>                 ostream = response.getOutputStream();
>>             } catch (IllegalStateException e) {
>>                 // If it fails, we try to get a Writer instead if we're
>>                 // trying to serve a text file
>>                 if ( (contentType == null)
>>                         || (contentType.startsWith("text"))
>>                         || (contentType.endsWith("xml")) ) {
>>                     writer = response.getWriter();
>>                 } else {
>>                     throw e;
>>                 }
>>             }
>>
>>
>> I think that if we fall back to using a Writer, the content-length
>> header must not be set by the DefaultServlet in the lines that follow
>> the above block of code.
>
> On what basis? It is just as likely that a Filter has called
> getOutputStream() as it is it called getWriter(). The Default Servlet
> has a 50/50 chance of calling the 'right' one first.
>

I thought about if (ostream != null) test before
response.setContentLength( ) call.

On second thought though, OK,
 I agree that it does not help much.


If some content was added before DefaultServlet was called:

1) We will not be able to process HEAD requests correctly.

In those cases we do not serve the resource, but Content-Length header
is returned.

Returning the content-length header consistently (and trimming the
output by that length) is the best what we can do here.


2) Support for the "Content-Range" header will be broken. (Unless
turned off in DefaultServlet configuration).

Best regards,
Konstantin Kolinko

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

Reply via email to