cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Only receive a header file

From: Jeff Pohlmeyer <yetanothergeek_at_gmail.com>
Date: Thu, 4 Mar 2010 11:02:06 -0600

On Thu, Mar 4, 2010 at 10:43 AM, Justin Skists wrote:
> On 4 March 2010 16:31, Olaf van der Spek wrote:

>> That's not a good idea.

> No, it's not. I regretted mentioning it as soon as I hit send. :)

The Content-Length header is really the only way to get an idea of
the file's size in advance, whether you use HEAD or GET.

Which one to use could depend on why you want this info, if you're
trying to make a decision about whether or not to download the file
at all, HEAD (CURLOPT_NOBODY) might be the better choice, but if you
just want the size for e.g. a progress meter, you may as well skip
the HEAD request and just grab the header from the GET response.

If the server doesn't send the header, then you simply won't know
the length, but that's no reason not to check for it. But it is
also possible that the server might get it wrong, perhaps because
of compression calculations, etc.

The expression that comes to mind is:
  "Hope for the best, but plan for the worst!"

- Jeff
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-03-04