curl-library
Adding CURLINFO_CONTENT_LENGTH to curl_getinfo()
Date: Thu, 01 Feb 2001 21:22:03 -0500
Dan,
I think I figured out how to add the ability to do a curl_easy_getinfo
and get a file's Content-Length value. The relevant code changes are
as follows:
Change the definition of this enum in curl/curl.h
to the following:
typedef enum {
CURLINFO_NONE, /* first, never use this */
CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1,
CURLINFO_HTTP_CODE = CURLINFO_LONG + 2,
CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3,
CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4,
CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5,
CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6,
CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7,
CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8,
CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9,
CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10,
CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11,
CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12,
CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13,
CURLINFO_FILETIME = CURLINFO_LONG + 14,
CURLINFO_CONTENT_LENGTH = CURLINFO_LONG + 15,
CURLINFO_LASTONE = 16
} CURLINFO;
Add the following case statement to curl_getinfo() in
lib/getinfo.c's switch(info) statement:
case CURLINFO_CONTENT_LENGTH:
*param_longp = (long)(data->progress.size_dl +
data->progress.size_ul);
break;
That's it. It seems to work for me. I had to dig into progress.c to
find these values, although the syntax may vary a bit from the
calculation of total_expected_transfer in progress.c.
I tried to implement this properly as a *param_doublep like
I thought it should be, but it would crash on me even when I
would statically set it's value to something like "1.0", so I
tried casting it to long and it worked. Should be OK since we
don't have to deal with fractional bytes yet! I am only using
this after a GET on headers only, can't tell how it would
function for other uses, but it eases the ability to automatically
test if a file PUT needs to be resumed.
Don't know if you ever got my request about adding this
feature as I still haven't received my copy from the list,
that's why I am emailing you directly in addition to the
list. I see 7.6.1-pre2 has been released, but this
functionality isn't included in it yet that I can see.
Bob Schader
_______________________________________________
Curl-library mailing list
Curl-library_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library
Received on 2001-02-02