Skip to content

Commit

Permalink
[server] No body when HEAD requests to healthcheck (#11183)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinus95 authored Jan 13, 2025
1 parent 75ebb61 commit dbcb983
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,18 @@ public void handle(HttpExchange httpExchange) throws IOException {
ServerMetricsCollector.getInstance().logFailedHealthcheck();
return;
} else {
String ok = "OK";
httpExchange.getResponseHeaders().set("Content-Type", "text/plain");
httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, ok.getBytes(ENCODING).length);
httpExchange.getResponseBody().write(ok.getBytes(ENCODING));

String requestMethod = httpExchange.getRequestMethod();
if ("HEAD".equalsIgnoreCase(requestMethod)) {
// Send HTTP 200 without content
httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, -1);
} else {
String ok = "OK";
httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, ok.getBytes(ENCODING).length);
httpExchange.getResponseBody().write(ok.getBytes(ENCODING));
}

ServerMetricsCollector.getInstance().logResponse(HttpURLConnection.HTTP_OK);
return;
}
Expand Down

0 comments on commit dbcb983

Please sign in to comment.