I’m pulling data from a server but need to know the type of data before I pull it. I know I can look at content-type in the response header, and I’ve looked into using
curl –head http://x.com/y/z
however some servers do not support the “HEAD” command (I get a 501 not implemented response).
Is it possible to somehow do a GET with curl, and immediately disconnect after all headers have been received?
Check out the following answer:
https://stackoverflow.com/a/5787827
Using this method you should be able to download as many bytes as you want, and then cancel the request. You could also work some magic to terminate after receiving a blank line, which would mean the end of the header.