cURL / Mailing Lists / curl-library / Single Mail


Using curl_eay_getinfo when msg->data.result == CURLE_OK

From: Chris Thomas <>
Date: Wed, 07 Jul 2004 16:39:13 +0100

Hi guys,

ok, I'm using libcurl in my application urlgrabber ( and I'm
trying to use it to give me the mime type of the file upon completion,
so I can do things like fail a download that is of type text/html for
example. I'm using the multi-interface

This is the code in question

while(running >= 0){
    while((cm = curl_multi_info_read(m_curl_multi,&num_msg)) != NULL){
        if(cm->msg == CURLMSG_DONE){
            int state;
            std::cout << GetFileType(cm->easy_handle) << std::endl;
            if(cm->data.result == CURLE_OK){
                state = COMPLETED;
                std::cout << "Download completed successfully" << std::endl;
                state = FAILED;
                std::cout << "Download failed for some reason" << std::endl;
            StopDownload(cm->easy_handle, state);
    if(running != 0) return true;
    else break;

the code for GetFileType is like this

std::string GetFileType(CURL *handle)
    std::cout << "GetFileType(handle)" << std::endl;
    std::string type = "unknown/binary";
    char *temp;
    CURLcode c = curl_easy_getinfo(handle,CURLINFO_CONTENT_TYPE,&temp);
    if(temp != NULL) type = temp;
    return type;

what is actually happening, is that when the curl message 'cm' has a
message CURLMSG_DONE it tries to obtain what type of file has just been
downloaded. it's not actually returning anything other than NULL from
this curl_easy_getinfo() function. I'm wondering why not and the value
I get it always unknown/binary.

I'd like to know, is there something I should know, cause I not retrieve
the data when the download has completed/failed/whatever, should I ask
curl for this information at the beginning rather than the end?

if anyone could help me out, that'd be great. If you wanna check this
code out as an application, you can goto and obtain the
unstable module from there, this code is in the Curl_Manager.[cpp/h]
files and you'll notice that yeah, I've modified this code here to strip
out anything unimportant to the problem, to make the code more readable.

Thanks guys!

Chris thomas
M.D. Antimatter Studios
Received on 2004-07-08