cURL / Mailing Lists / curl-library / Single Mail

curl-library

Write function called after abort

From: James Bursa <james_at_semichrome.net>
Date: Sat, 13 Aug 2005 19:44:49 +0100

I've found a case where the callback set by CURLOPT_WRITEFUNCTION is
called once after a previous call returned 0 to abort the transfer.

The example below usually reproduces the problem, which appears to be
triggered by the server sending a response with no headers, not even
an HTTP status line. Occasionally the URL below returns a redirect
instead, presumably because it is serving random adverts.

The output I get is at the end of this message. I'm using 7.14.0.

James

______________________________________________________________________

#include <stdio.h>
#include <curl/curl.h>

size_t callback(void *ptr, size_t size, size_t nmemb, void *data);

int main(int argc, char **argv)
{
  CURL *curl;

  curl_global_init(CURL_GLOBAL_ALL);

  curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  curl_easy_setopt(curl, CURLOPT_URL,
"http://www.burstnet.com/cgi-bin/ads/ad8451a.cgi/ns/v=2.0S/sz=468x60A|728x90A/")
;
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback);
  curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0");
  curl_easy_perform(curl);
  curl_easy_cleanup(curl);

  return 0;
}

size_t callback(void *ptr, size_t size, size_t nmemb, void *data)
{
  printf("callback: size %lu, nmemb %lu\n", size, nmemb);
  return 0;
}
______________________________________________________________________

* About to connect() to www.burstnet.com port 80
* Trying 212.203.28.217... * connected
* Connected to www.burstnet.com (212.203.28.217) port 80
> GET /cgi-bin/ads/ad8451a.cgi/ns/v=2.0S/sz=468x60A|728x90A/ HTTP/1.1
User-Agent: Mozilla/4.0
Host: www.burstnet.com
Accept: */*

callback: size 1, nmemb 151
* Failed writing body
callback: size 1, nmemb 1297
* Failed writing body
* Closing connection #0
Received on 2005-08-13