Skip to content

Allow HEAD method for /health endpoint, referencing Node.js health check best practices #178

@ovidiul

Description

@ovidiul

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions