]> nmode's Git Repositories - signal-cli/commitdiff
Add alive check (#1107)
authorced-b <cedric@cos.flag.org>
Tue, 22 Nov 2022 06:58:34 +0000 (01:58 -0500)
committerGitHub <noreply@github.com>
Tue, 22 Nov 2022 06:58:34 +0000 (07:58 +0100)
Adds a simple HTTP endpoint that can be used by the container
environment to see if the app is started and available.

Co-authored-by: cedb <cedb@keylimebox.org>
src/main/java/org/asamk/signal/http/HttpServerHandler.java

index f7f2768d6bffdf21312d7557af758982ecce2a6e..a62139291e36e1394e02698682c1536bd6a14fca 100644 (file)
@@ -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<Manager> getManagerFromQuery(final Map<String, String> query) {
         List<Manager> managers;
         if (m != null) {