I am using php curl to check if a user-supplied URL is valid. See this question for specific/gory details. That question got an answer that I accepted - that the error-checking was way too complex and I should just use file_get_contents() instead of curl. That works for the sole purpose of a good/bad determination, but it doesn't provide useful information to the user, like whether the domain doesn't exist, the resource was not found, needs authorization, etc. So I intend to post a different curl-based answer and remove the accepted status from the one suggesting file_get_contents().
But then I came across the following problem with a URL for a site that I own: curl rejected it with the following error recorded in the verbose log:
* http2 error: Invalid HTTP header field was received: frame type: 1, stream: 1, name: [upgrade], value: [h2,h2c]
Tracking that down, it apparently is triggered because the http2 RFC forbids connection-specific headers in responses. I can "fix" it by adding proxy_hide_header: Upgrade;
to the site's nginx configuration. But the site works fine in web browsers, and what I'm trying to do is determine whether or not a URL will work in a web browser.
I suppose I could write even more code to save the verbose messages from the curl request and scan them for http2 errors, but that seems insanely complicated. What can I do on the curl end to prevent having the URL rejected for this reason?