2

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?

Martin Konecny
  • 57,827
  • 19
  • 139
  • 159

1 Answers1

2

Check out the following answer:

https://stackoverflow.com/a/5787827

Streaming. UNIX philosphy and pipes: they are data streams. Since curl and GET are unix filters, ending the receiving pipe (dd) will terminate curl or GET early (SIGPIPE). There is no telling whether the server will be smart enough to stop transmission. However on a TCP level I suppose it would stop retrying packets once there is no more response. @sehe

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.

Community
  • 1
  • 1
travis
  • 8,055
  • 1
  • 17
  • 19