Skip to content
Permalink
Browse files

Proper exception handling

  • Loading branch information...
evgk committed Nov 22, 2018
1 parent fd80618 commit 0e74d0329f42a4cdb590c93b02820542612a7684
Showing with 19 additions and 4 deletions.
  1. +19 −4 core/src/main/java/org/nanohttpd/protocols/http/response/Response.java
@@ -297,17 +297,32 @@ private void sendBodyWithCorrectTransferAndEncoding(OutputStream outputStream, l
if (this.requestMethod != Method.HEAD && this.chunkedTransfer) {
ChunkedOutputStream chunkedOutputStream = new ChunkedOutputStream(outputStream);
sendBodyWithCorrectEncoding(chunkedOutputStream, -1);
chunkedOutputStream.finish();
try {
chunkedOutputStream.finish();
} catch (Exception e) {
if(this.data != null) {
this.data.close();
}
}
} else {
sendBodyWithCorrectEncoding(outputStream, pending);
}
}

private void sendBodyWithCorrectEncoding(OutputStream outputStream, long pending) throws IOException {
if (useGzipWhenAccepted()) {
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
sendBody(gzipOutputStream, -1);
gzipOutputStream.finish();
GZIPOutputStream gzipOutputStream = null;
try {
gzipOutputStream = new GZIPOutputStream(outputStream);
} catch (Exception e) {
if(this.data != null) {
this.data.close();
}
}
if (gzipOutputStream != null) {
sendBody(gzipOutputStream, -1);
gzipOutputStream.finish();
}
} else {
sendBody(outputStream, pending);
}

0 comments on commit 0e74d03

Please sign in to comment.
You can’t perform that action at this time.