Skip to content

Commit

Permalink
ee10: DefaultServlet: Replace checks for isStreaming() by !isWriting()
Browse files Browse the repository at this point in the history
Checking for isStreaming() will return false even when no data has been
written yet. This erroneously triggers double-encoding of binary data in
a Writer.

If the Writer is not set to ISO-8859-1 or similar, the output will be
corrupted, causing errors like "java.io.IOException: written
25746 > 12014 content-length", and interrupted transmissions.

Replace the isStreaming() check by !isWriting().

#9134

Signed-off-by: Christian Kohlschütter <[email protected]>
  • Loading branch information
kohlschuetter authored and lorban committed Jan 10, 2023
1 parent 177bafb commit 12d4573
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,10 @@ public boolean isWritingOrStreaming()
return servletContextResponse.isWritingOrStreaming();
}

public boolean isStreaming()
public boolean isWriting()
{
ServletContextResponse servletContextResponse = Response.as(_coreResponse, ServletContextResponse.class);
return servletContextResponse.isStreaming();
return servletContextResponse.isWriting();
}

@Override
Expand All @@ -815,13 +815,7 @@ public void write(boolean last, ByteBuffer byteBuffer, Callback callback)
{
if (BufferUtil.hasContent(byteBuffer))
{
if (isStreaming())
{
BufferUtil.writeTo(byteBuffer, _response.getOutputStream());
if (last)
_response.getOutputStream().close();
}
else
if (isWriting())
{
String characterEncoding = _response.getCharacterEncoding();
try (ByteBufferInputStream bbis = new ByteBufferInputStream(byteBuffer);
Expand All @@ -833,6 +827,12 @@ public void write(boolean last, ByteBuffer byteBuffer, Callback callback)
if (last)
_response.getWriter().close();
}
else
{
BufferUtil.writeTo(byteBuffer, _response.getOutputStream());
if (last)
_response.getOutputStream().close();
}
}

callback.succeeded();
Expand Down

0 comments on commit 12d4573

Please sign in to comment.