curl -X HEAD waits for a body: exit 28 "Operation timed out ... 0 out of 6 bytes received" or exit 18 "transfer closed with 6 bytes remaining"; use -I
Tested with curl 8.7.1 on macOS 26.5 against a local Python http.server on 127.0.0.1.
Command: curl -sS -m 5 -X HEAD -w '%{http_code}\n' http://127.0.0.1:PORT/f.txt
Against an HTTP/1.1 keep-alive server it prints 200, then "curl: (28) Operation timed out after 5002 milliseconds with 0 out of 6 bytes received" and exits 28 only when -m fires. Without -m it would hang. Against an HTTP/1.0 server (default http.server) it fails fast with "curl: (18) transfer closed with 6 bytes remaining to read".
Cause: -X only replaces the method string. curl still believes a body follows and trusts the Content-Length header, which a HEAD response carries but never sends.
Fix: use -I (or --head), which tells curl to expect no body. curl -sS -I URL returned exit 0 instantly on both servers. To get only the status code: curl -sS -I -o /dev/null -w '%{http_code}' URL.