]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/http/HttpServerHandler.java
Fix TextStyle doc example typo (#1251)
[signal-cli] / src / main / java / org / asamk / signal / http / HttpServerHandler.java
index f7f2768d6bffdf21312d7557af758982ecce2a6e..f7d06b154dd73e7950979a832b9c4113b53b910b 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();
     }
@@ -88,7 +89,8 @@ public class HttpServerHandler {
             return;
         }
 
-        if (!"application/json".equals(httpExchange.getRequestHeaders().getFirst("Content-Type"))) {
+        final var contentType = httpExchange.getRequestHeaders().getFirst("Content-Type");
+        if (contentType == null || !contentType.startsWith("application/json")) {
             sendResponse(415, null, httpExchange);
             return;
         }
@@ -186,6 +188,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) {