cURL / Mailing Lists / curl-library / Single Mail

curl-library

CURLOPT_WRITEFUNCTION callback not called when If-Modified-Since not obeyed

From: Steve Liao <steve_at_broadsoft.com>
Date: Thu, 12 May 2011 13:49:32 -0700

Hi,

My application uses CURL_TIMECOND_IFMODSINCE. When the HTTP server returns a 304 in response to an HTTP GET in which the If-Modified-Since header is the same time as the last modification time of the file, things are fine.

However, when an HTTP server that doesn't obey that header returns a 200 response and provides the file content, the callback registered against CURLOPT_WRITEFUNCTION doesn't get called even though there is file content. This behavior is observed on libcurl 7.21.6. When the application is built against libcurl 7.17.1, this beahavior doesn't show up - the callback registered against CURLOPT_WRITEFUNCTION gets called.

Has anyone encountered this? Is this a bug that got introduced sometime after 7.17.1, or does the application need to be updated? If so, what's the correct way to handle this new behavior?

The application uses the libcurl easy interface. Below is a C code snippet showing the options set and the invocation to perform the get.

Any insights would be real helpful.

void *curlHandle = initHandle();

CURLcode result = curl_easy_setopt( curlHandle, CURLOPT_FILETIME, 1 );
assert( result == CURLE_OK );

result = curl_easy_setopt( curlHandle, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE );
assert( result == CURLE_OK );

CURLcode result = curl_easy_setopt( curlEasyHandle, CURLOPT_WRITEFUNCTION, &copyToBuffer );
assert( result == CURLE_OK );

result = curl_easy_setopt( curlEasyHandle, CURLOPT_HEADERFUNCTION, &parseHeader );
assert( result == CURLE_OK );

result = curl_easy_setopt( curlEasyHandle, CURLOPT_WRITEDATA, &networkObject );
assert( result == CURLE_OK );

result = curl_easy_setopt( curlEasyHandle, CURLOPT_HEADERDATA, &networkObject );
assert( result == CURLE_OK );

result = curl_easy_setopt( curlEasyHandle, CURLOPT_TIMEVALUE, lastModifiedDate );
assert( result == CURLE_OK );

CURLcode result = curl_easy_setopt( curlEasyHandle, CURLOPT_URL, url.c_str() );
if (result != CURLE_OK) {
  // throw an exception
}

// Start download
result = curl_easy_perform( curlEasyHandle );

if (result == CURLE_OK) {

  // Get response code
  long responseCode;
  result = curl_easy_getinfo( curlEasyHandle, CURLINFO_RESPONSE_CODE, &responseCode );
  assert( result == CURLE_OK );

  // responseCode is 200
    . . . .
}

Many Thanks,
Steve

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-05-12