cURL / Mailing Lists / curl-library / Single Mail

curl-library

CURLINFO_CONTENT_LENGTH_DOWNLOAD bug

From: Allen Pulsifer <pulsifer3_at_comcast.net>
Date: Thu, 28 Jun 2007 19:57:02 -0400

I'm using libcurl v7.16.2 for http requests.

As soon as I receive the "empty" header (nbytes == 2) via
CURLOPT_HEADERFUNCTION, I'm using curl_easy_getinfo() to fetch info about
the response. One of the values I need is CURLINFO_CONTENT_LENGTH_DOWNLOAD.

curl_easy_getinfo(CURLINFO_CONTENT_LENGTH_DOWNLOAD) fetches
"progress.size_dl". libcurl sets this value by calling
Curl_pgrsSetDownloadSize(). The problem I'm having is that
Curl_pgrsSetDownloadSize is not called immediately, when the
"Content-Length" header is parsed, its called sometime later and has not
been set by the time libcurl sends my application the last (empty) header.

Is there any reason in particular that Curl_pgrsSetDownloadSize() is not set
immediately when the "Content-Length" header is parsed?

Its currently being set in transfer.c at line 675. This section of the code
reads:

                if(-1 != k->size) {
                  /* We do this operation even if no_body is true, since
this
                     data might be retrieved later with curl_easy_getinfo()
                     and its CURLINFO_CONTENT_LENGTH_DOWNLOAD option. */

                  Curl_pgrsSetDownloadSize(data, k->size);
                  k->maxdownload = k->size;
                }

I think it should be set instead at transfer.c line 850, where the
"Content-Length" header is detected. This section of code reads:

            /* Check for Content-Length: header lines to get size. Ignore
               the header completely if we get a 416 response as then we're
               resuming a document that we don't get, and this header
contains
               info about the true size of the document we didn't get now.
*/
            if (!k->ignorecl && !data->set.ignorecl &&
                checkprefix("Content-Length:", k->p)) {
              contentlength = curlx_strtoofft(k->p+15, NULL, 10);
              if (data->set.max_filesize &&
                  contentlength > data->set.max_filesize) {
                failf(data, "Maximum file size exceeded");
                return CURLE_FILESIZE_EXCEEDED;
              }
              if(contentlength >= 0) {
                k->size = contentlength;
                k->maxdownload = k->size;
              }

I tried inserting a call to Curl_pgrsSetDownloadSize(data, k->size) at
transfer.c line 852, and it seems to work fine.
Received on 2007-06-29