cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Only receive a header file

From: Olaf van der Spek <olafvdspek_at_gmail.com>
Date: Thu, 4 Mar 2010 17:31:22 +0100

On Thu, Mar 4, 2010 at 5:24 PM, Justin Skists <j.skists_at_googlemail.com> wrote:
>
>
> On 4 March 2010 00:13, dylan <glethro_at_gmail.com> wrote:
>>
>> Hello,
>> I'm working on a small program that needs to know the size of a file
>> before it is downloaded via HTTP. The header file for these files does
>> contain this information, so i was wondering if it is possible to only
>> receive the header without the rest of the data.
>> If so, how is that done?
>>
>
> Use the CURLOPT_NOBODY option for curl_easy_setopt, to create a HEAD request
> instead of a GET, to return just the headers.
>
> Or, since headers usually come in before the data, you could read the
> Content-Length header (through CURLOPT_HEADERFUNCTION) and act on it before
> the data arrives (though CURLOPT_WRITEFUNCTION)? (Not 100% cetain that will
> be the case)

That's not a good idea.

Either way, there might not be a content-length header.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-03-04