however, for HTTPS, there is no way to make it work.
curl -H "Host: direct.openfreemap.org" -I https://144.76.168.195/styles/liberty
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
The only way to make it work with HTTPS is to use the special, low-level "resolve" option with curl:
My problem is that while it works with curl, I cannot do the same in a JS environment, for example in a Cloudflare worker. I'm trying to use Cloudflare workers to health-check individual servers behind a Round-Robin DNS record, and this would be the only way.
Can you tell me how does HTTPS work, or how can I possibly fix this? The "Host" header is definitely not enough.
Why are you using an IP in the URL instead of the name on the cert?
If the name doesn't resolve to that IP, then you can override it locally in the /etc/hosts file.
headers, host or whatever it will be is http layer thing, and TLS layer ignores it: if you call curl by IP address it will send request with any server name indication, so server have to return default certificate that's likely not valid for your expected name
Maybe it's as simple as a SNI issue. As far as I can tell from man curl, the -H Host ... option does not change anything with relation to the SNI value.
Thus a curl command with the https://hostname/ is required to set hostname as the SNI value and if OP then needs to do some fancy resolving using --resolve due to their internal shenanigans, well, that's just that
Maybe OP needs to Google/DuckDuckGo/ChatGPT with keywords sni and javascript to fix their JS environment, I dunno..
Maybe it's as simple as using and setting tlsSocket.servername in their Node.js (assuming they're using Node.js) script Or maybe set the hostname property/context with server.addContext(), I dunno, I don't "speak" Node.js.. There are 17 mentions of sni on TLS (SSL) | Node.js v22.2.0 Documentation, so probably enough to read about.