cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: http error with CURLOPT_RESUME_FROM CURLOPT_FAILONERROR

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Tue, 25 Nov 2003 08:31:46 +0100 (CET)

On Mon, 24 Nov 2003, zach diubaldo wrote:

> Hey all, I am having some problems with downloading a file and using
> CURLOPT_FAILONERROR and CURLOPT_RESUME_FROM at the same time.

... using what libcurl version on what platform?

> curl_easy_setopt( pcurl, CURLOPT_CONNECTTIMEOUT, 60 );
> curl_easy_setopt( pcurl, CURLOPT_FAILONERROR, TRUE );
> curl_easy_setopt( pcurl, CURLOPT_RESUME_FROM, file_size );
> curl_easy_setopt( pcurl, CURLOPT_BUFFERSIZE, 14000 );
> curl_status = curl_easy_perform( pcurl );
>
> My problem is when the file has already been downloaded. I use the return
> from curl_easy_perform() to determine if file that I am download exits, if
> it doesn't curl_status = CURLE_HTTP_RETURNED_ERROR. That is what I would
> expect and that is good by me. The problem occurs when the file is valid,
> but has already been downloaded. Even if the file has been downloaded in
> full the above code is executed. When it does curl_status =
> CURLE_HTTP_RETURNED_ERROR.

The problem with using this approach is that HTTP servers normally actually DO
return an error for this kind of operation. I've had a hard time to actually
decide what libcurl should do on this use case (and make it consistent with
how it works for FTP).

The problem is that when you try to resume from 'file size' the HTTP server
will return an error saying that you've tried to download a range that is
outside the file's size. In 7.10.8 I've tried to deal with this (HTTP error
code 416), but I'm not 100% satisfied yet as I'm having a hard time deciding
what the correct behavior should be.

> I guess I could grab the size of the file from the http headers and not
> download if I already have the file, but I would rather not have to parse
> the http header to find the size. Any one have any thoughts on this?

At the moment I don't think I can come up with a better idea.

-- 
    Daniel Stenberg -- http://curl.haxx.se/ -- http://daniel.haxx.se/
 [[ Do not post private mails to this email address. They won't reach me. ]]
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Received on 2003-11-25