From 44f4452c3f43e727bbda255f094d5920b01730e5 Mon Sep 17 00:00:00 2001 From: cedb Date: Mon, 21 Nov 2022 23:38:55 -0500 Subject: [PATCH] Add alive check Adds a simple HTTP endpoint that can be used by the container environment to see if the app is started and available. --- .../org/asamk/signal/http/HttpServerHandler.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/asamk/signal/http/HttpServerHandler.java b/src/main/java/org/asamk/signal/http/HttpServerHandler.java index f7f2768d..a6213929 100644 --- a/src/main/java/org/asamk/signal/http/HttpServerHandler.java +++ b/src/main/java/org/asamk/signal/http/HttpServerHandler.java @@ -59,6 +59,7 @@ public class HttpServerHandler { server.createContext("/api/v1/rpc", this::handleRpcEndpoint); server.createContext("/api/v1/events", this::handleEventsEndpoint); + server.createContext("/api/v1/check", this::handleCheckEndpoint); server.start(); } @@ -186,6 +187,19 @@ public class HttpServerHandler { } } + private void handleCheckEndpoint(HttpExchange httpExchange) throws IOException { + if (!"/api/v1/check".equals(httpExchange.getRequestURI().getPath())) { + sendResponse(404, null, httpExchange); + return; + } + if (!"GET".equals(httpExchange.getRequestMethod())) { + sendResponse(405, null, httpExchange); + return; + } + + sendResponse(200, null, httpExchange); + } + private List getManagerFromQuery(final Map query) { List managers; if (m != null) {