Skip to content

Commit

Permalink
Added try/finally to close the HttpExchange
Browse files Browse the repository at this point in the history
Signed-off-by: dhoard <[email protected]>
  • Loading branch information
dhoard committed Mar 21, 2024
1 parent 8bb7544 commit d84b0fa
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 d84b0fa

Please sign in to comment.