I need to create a reliable test to see if the current host can reach the public internet using HTTP (port 80) or HTTPS (port 443).
This is not a programming language question. I got that part covered.
My idea is that I'll test against something on the public internet that
Is always alive
Can respond to HTTP or HTTPS requests
Can respond fast (I'm thinking I'll do a HEAD request to keep the reply small)
Will exist also in a forseable future
What would that endpoint be? Is there some official server that can make the above promises, e.g. something provided by w3.org ? (I know that people tend to use www.google.com
or similar but doesn't sound to me to be a good solution, or?..).
Further my thinking is:
Not to use something like a ping test because ICMP is blocked by many firewalls.
Probably needs to be a true HTTP/HTTPS request in order to go through a potential firewall. A plain socket test might give false result if there's a firewall in-between. So I'll do a true HTTP/HTTPS test. My HTTPS test will ignore certs because that's not what I want to test.
No matter what I do I'll also indirectly be testing name resolution (unless I'm testing against an IP address which I find unlikely). This is ok. Name resolution is in any case also part of "internet connectivity".
What would be the most reliable way to perform an internet connectivity test (I only care about HTTP and HTTPS) and which endpoint should I use ?
I'm assuming that thousands of developers before me have tackled this. But how?
UPDATE AND FINAL SOLUTION
It seems I will not get anyone answering with an official endpoint to use for this purpose (perhaps there just isn't one?) so what I'll do is to send a HTTP HEAD request to google.com
. My request will have HTTP header element cache-control: no-cache
hoping to avoid any in-between proxies answering me from their own cache. I'll then repeat exactly the same test for HTTPS.
There's no such thing as a perfect test but from my requirements the above is what seems to come closest.
Thanks to anyone who has answered.