-
Notifications
You must be signed in to change notification settings - Fork 218
Open
Description
Currently, the /health endpoint only allows the GET method. To follow best practices for Node.js health checks (see reference), the endpoint should also support the HEAD method. This would allow automated systems and load balancers to use lightweight HEAD requests for health checks without receiving a response body.
Recommended changes:
- Update the HTTP handler for /health to accept both GET and HEAD methods.
- For HEAD requests, respond with the appropriate status and headers, but no response body (per HTTP/1.1 spec).
- Reference: https://docs.wpvip.com/node-js/health-checks/
Example implementation:
if ((req.method === "GET" || req.method === "HEAD") && url.pathname === path) {
res.writeHead(healthConfig.status ?? 200, {
"Content-Type": "text/plain",
});
if (req.method === "GET") {
res.end(healthConfig.message ?? "✓ Ok");
} else {
res.end(); // HEAD: Send headers only, no body
}
return;
}
This change will improve compatibility with health checks and monitoring systems that rely on HEAD requests.
Thanks for considering this.
Metadata
Metadata
Assignees
Labels
No labels