cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: really dumb question I'm sure

From: Andrew Francis <locust_at_familyhealth.com.au>
Date: Fri, 28 Mar 2003 11:19:35 +0800

On Thu, Mar 27, 2003 at 03:46:21PM -0500, josh.m.daynard_at_accenture.com wrote:
> So my question is: is there anyway in libcurl to just tell it not to bother
> writing the response anywhere?

Define a custom callback function that does nothing:

extern "C" { // use this if, and only if, you're writing C++
        
size_t callback_noop(void *p, size_t s, size_t nmemb, void *stream) {
        return s * nmemb;
}

} // ditto re: c++

// when about to curl_easy_perform:
curl_easy_setopt(curlHandle, CURLOPT_FILE, NULL);
curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curl_noop);
curl_easy_setopt(curlHandle, CURLOPT_HEADERFUNCTION, callback_noop);

This will actually still download all the data though. If you like,
you can get the callback function to cancel the download operation.
You'll get an error returned from curl_easy_perform, but it means
curl won't bother downloading all the data from the web server

size_t callback_noop(void *p, size_t s, size_t nmemb, void *stream) {
        return 0; /* abort transfer */
}

-- 
Andrew Francis
Software Developer
Family Health Network
-------------------------------------------------------
This SF.net email is sponsored by:
The Definitive IT and Networking Event. Be There!
NetWorld+Interop Las Vegas 2003 -- Register today!
http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
Received on 2003-03-28