chore: Add undici package and update health check service to utilize undici's Agent for improved HTTP probing
Build, Test, and Push CFDM Docker Image / test (push) Successful in 4m9s
Build, Test, and Push CFDM Docker Image / build-and-push (push) Successful in 2m58s
Build, Test, and Push CFDM Docker Image / update-wiki (push) Successful in 9s
Build, Test, and Push CFDM Docker Image / create-release (push) Has been skipped

This commit is contained in:
Denozordec
2026-06-26 00:15:22 +07:00
parent 43d473c520
commit a0380b3f66
3 changed files with 31 additions and 1 deletions
+1
View File
@@ -26,6 +26,7 @@
"p-limit": "^6.2.0",
"p-queue": "^8.1.0",
"toad-scheduler": "^4.0.1",
"undici": "^8.5.0",
"zod": "^4.2.0"
},
"devDependencies": {
+21 -1
View File
@@ -1,4 +1,5 @@
import { connect } from "node:net";
import { Agent } from "undici";
import type { Db } from "@cfdm/db";
import { repos } from "@cfdm/db";
import type { HealthCheckTarget, IpHealthState } from "@cfdm/shared";
@@ -64,14 +65,33 @@ async function httpProbe(
): Promise<ProbeResult> {
const started = Date.now();
const path = target.path?.trim() || "/";
const url = `http://${ip}${path.startsWith("/") ? path : `/${path}`}`;
const pathWithSlash = path.startsWith("/") ? path : `/${path}`;
const port = target.port ?? 80;
const hostHeader = target.hostname || ip;
const useTls = port === 443;
// For HTTPS probing against a raw IP, set SNI/Host so TLS handshake and vhost routing work.
const authorityHost = target.hostname || ip;
const url = useTls
? `https://${authorityHost}${pathWithSlash}`
: `http://${ip}${pathWithSlash}`;
// Custom dispatcher for HTTPS-to-IP: connect to the literal IP, but present hostname via SNI.
const dispatcher =
useTls && target.hostname
? new Agent({
connect: {
servername: target.hostname,
rejectUnauthorized: false,
},
})
: undefined;
try {
const response = await fetch(url, {
method: "GET",
headers: { Host: hostHeader },
signal: AbortSignal.timeout(timeoutMs),
redirect: "manual",
// @ts-expect-error undici dispatcher option is not in fetch types
dispatcher,
});
const latency = Date.now() - started;
if (target.expected_status != null) {
+9
View File
@@ -66,6 +66,9 @@ importers:
toad-scheduler:
specifier: ^4.0.1
version: 4.0.1
undici:
specifier: ^8.5.0
version: 8.5.0
zod:
specifier: ^4.2.0
version: 4.4.3
@@ -3763,6 +3766,10 @@ packages:
undici-types@7.18.2:
resolution: {integrity: sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==}
undici@8.5.0:
resolution: {integrity: sha512-xamtWoB1EshgjpmlXd7GGm2VfdDtw1+rD8uhry8pSNW3If6S8E0m2T2+orSKeZXEn/aPJMviCpDBA65WJt8zhg==}
engines: {node: '>=22.19.0'}
unplugin@3.0.0:
resolution: {integrity: sha512-0Mqk3AT2TZCXWKdcoaufeXNukv2mTrEZExeXlHIOZXdqYoHHr4n51pymnwV8x2BOVxwXbK2HLlI7usrqMpycdg==}
engines: {node: ^20.19.0 || >=22.12.0}
@@ -7095,6 +7102,8 @@ snapshots:
undici-types@7.18.2: {}
undici@8.5.0: {}
unplugin@3.0.0:
dependencies:
'@jridgewell/remapping': 2.3.5