From e0a1cf765752bc8d9bf4ff0e00e6bb53cf7c9e77 Mon Sep 17 00:00:00 2001 From: Azmy Date: Tue, 21 Jan 2025 14:22:16 +0200 Subject: [PATCH] Add `/healthz` endpoint for basic health check in S3Proxy - Implemented a new `/healthz` endpoint to handle GET requests. - Added the `handleVersionRequest` method to return a JSON response with health status: - Response: `{ "status": "OK" }` - Updated `S3ProxyHandler` to route requests to `/healthz` and handle responses effectively. - The endpoint provides a simple mechanism for health monitoring and status validation. --- .../java/org/gaul/s3proxy/S3ProxyHandler.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java index 23332575..e9e1889d 100644 --- a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java +++ b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java @@ -293,6 +293,12 @@ public final void doHandle(HttpServletRequest baseRequest, String uri = request.getRequestURI(); String originalUri = request.getRequestURI(); + // Check for the /version endpoint + if ("/healthz".equals(uri) && "GET".equalsIgnoreCase(method)) { + handleVersionRequest(response); + return; + } + if (!this.servicePath.isEmpty()) { if (uri.length() > this.servicePath.length()) { uri = uri.substring(this.servicePath.length()); @@ -2029,6 +2035,18 @@ private void handlePutBlob(HttpServletRequest request, response.addHeader(HttpHeaders.ETAG, maybeQuoteETag(eTag)); } + private void handleVersionRequest(HttpServletResponse response) throws IOException { + response.setStatus(HttpServletResponse.SC_OK); + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + + String versionInfo = "{ \"status\": \"OK\"}"; + + try (PrintWriter writer = response.getWriter()) { + writer.write(versionInfo); + writer.flush(); + } + } private void handlePostBlob(HttpServletRequest request, HttpServletResponse response, InputStream is, BlobStore blobStore,