Skip to content

Commit

Permalink
Merge pull request #932 from dhoard/issue-924
Browse files Browse the repository at this point in the history
Added try/finally to close the HttpExchange
  • Loading branch information
dhoard authored Mar 21, 2024
2 parents 8bb7544 + d84b0fa commit 7998f12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public DefaultHandler() {

@Override
public void handle(HttpExchange exchange) throws IOException {
exchange.getResponseHeaders().set("Content-Type", contentType);
exchange.getResponseHeaders().set("Content-Length", Integer.toString(responseBytes.length));
exchange.sendResponseHeaders(200, responseBytes.length);
exchange.getResponseBody().write(responseBytes);
exchange.close();
try {
exchange.getResponseHeaders().set("Content-Type", contentType);
exchange.getResponseHeaders().set("Content-Length", Integer.toString(responseBytes.length));
exchange.sendResponseHeaders(200, responseBytes.length);
exchange.getResponseBody().write(responseBytes);
} finally {
exchange.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public HealthyHandler() {

@Override
public void handle(HttpExchange exchange) throws IOException {
exchange.getResponseHeaders().set("Content-Type", contentType);
exchange.getResponseHeaders().set("Content-Length", Integer.toString(responseBytes.length));
exchange.sendResponseHeaders(200, responseBytes.length);
exchange.getResponseBody().write(responseBytes);
exchange.close();
try {
exchange.getResponseHeaders().set("Content-Type", contentType);
exchange.getResponseHeaders().set("Content-Length", Integer.toString(responseBytes.length));
exchange.sendResponseHeaders(200, responseBytes.length);
exchange.getResponseBody().write(responseBytes);
} finally {
exchange.close();
}
}
}

0 comments on commit 7998f12

Please sign in to comment.