cURL / Mailing Lists / curl-library / Single Mail

curl-library

Response head is not retrievable

From: Nikolai Kondrashov <Nikolai.Kondrashov_at_oktetlabs.ru>
Date: Thu, 03 Apr 2008 10:17:31 +0400

Hello All,

It seems that response head cannot be retrieved if custom function is used
to retrieve the body. At least with 7.18.0. Assigning a custom head
retrieval function doesn't help.

We cannot use HEAD method, because we need a POST response head, but don't
need the body. Currently, I'm simply sending the body to /dev/null, but it
is inconvenient and non-portable. If this is the way it should work, then it
should be mentioned in the documentation.

Below is a demonstration:
---:<---
#include <stdio.h>
#include <curl/curl.h>

#define SHOW_BUG

#ifdef SHOW_BUG
size_t
write_cb(void *ptr, size_t size, size_t nmemb, void *stream)
{
     (void)ptr;
     (void)stream;

     return nmemb * size;
}
#endif

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

#ifndef SHOW_BUG
     FILE *data_file = NULL;

     data_file = fopen("/dev/null", "w");

     curl = curl_easy_init();

     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
     curl_easy_setopt(curl, CURLOPT_WRITEDATA, data_file);
#else
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
     curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
#endif

     curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout);

     curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");

     curl_easy_perform(curl);
     curl_easy_cleanup(curl);

#ifndef SHOW_BUG
     fclose(data_file);
#endif

     return 0;
}
--->:---

I'm sorry if this bug is already known or even fixed. I wasn't able to find
it in your bug tracker and do not dare to break my environment by installing
the latest libcurl.

Sincerely,
Nick
Received on 2008-04-03