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.
> That said, I am not sure why anybody should rely on DefaultServlet
> being able to serve the resource in this case at all. It is a nice
> feature, though.
It has to be able to handle both cases where a Filter calls getWriter()
or getOutputStream()?
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]