Permalink
Browse files

Merge pull request #525 from evgk/patch-1

Proper exception handling
  • Loading branch information...
LordFokas committed Nov 23, 2018
2 parents fd80618 + 0e74d03 commit b04a342a4bcd0ff44be65138acffc73a29381c72
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 b04a342

Please sign in to comment.