Skip to content

Commit

Permalink
BL-714
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Nov 6, 2024
1 parent 6f23571 commit 0ff0936
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public class BoxHTTPServletExchange implements IBoxHTTPExchange {
*/
List<FileUpload> fileUploads = new ArrayList<FileUpload>();

/**
* PrintWriter for the response that wraps the servlet's
*/
WhitespaceManagingPrintWriter writer;

/**
* Create a new BoxLang HTTP exchange for a Servlet
*
Expand Down Expand Up @@ -194,6 +199,9 @@ public void flushResponseBuffer() {
setResponseHeader( "Content-Type", "text/html;charset=UTF-8" );
}

// Update this in case the content type has changed
writer.setWhitespaceCompressionEnabled( boxContext.isWhitespaceCompressionEnabled() );
writer.flush();
response.flushBuffer();
} catch ( IOException e ) {
throw new BoxRuntimeException( "Could not flush response buffer", e );
Expand Down Expand Up @@ -525,14 +533,20 @@ public int getResponseStatus() {

@Override
public PrintWriter getResponseWriter() {
try {
return response.getWriter();
} catch ( IOException e ) {
throw new BoxRuntimeException( "Could not get response writer", e );
} catch ( IllegalStateException e ) {
// reponse has already been sent, so return a dummy writer
return new PrintWriter( NullWriter.INSTANCE );
if ( writer == null ) {
PrintWriter servletWriter;

try {
servletWriter = response.getWriter();
} catch ( IOException e ) {
throw new BoxRuntimeException( "Could not get response writer", e );
} catch ( IllegalStateException e ) {
// reponse has already been sent, so return a dummy writer
servletWriter = new PrintWriter( NullWriter.INSTANCE );
}
writer = new WhitespaceManagingPrintWriter( servletWriter, boxContext.isWhitespaceCompressionEnabled() );
}
return writer;
}

@Override
Expand Down

0 comments on commit 0ff0936

Please sign in to comment.