cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: HTTP GET method without body

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 9 Dec 2015 23:10:37 +0100 (CET)

On Wed, 9 Dec 2015, Boris Schrijver wrote:

> What I basically want is: curl -X GET -I http://random.url/object

Append "--libcurl test.c" on that command line and you'll see how to write
code for it. Although I suspect you may confuse libcurl a bit by doing that so
the next request on the same connection will probably first have to detect
that there's pending data which will make think it died, then close the
connection and create a new one.

> I tried to implement it in qemu-img [2] but ended up always getting a
> CURLE_WRITE_ERROR, due to the body not being written anywhere.

That's because you cut off the response and that makes it a transfer error.
There's no way around that.

But you can easily set a flag or something before you return that error that
cuts off the body, and then when you see CURLE_WRITE_ERROR you check if that
flag was set and then you know it was on purpose. Done!

> Is it possible to include a curl_easy_setopt() option to discard the response
> body and stop the connection after the HEADER?

Nope. And I don't see the point in adding such an option either, as you can
easily implement this yourself as described above.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2015-12-09