cURL / Mailing Lists / curl-library / Single Mail

curl-library

setting POSTFIELDS to NULL forces PUT instead of GET - please document

From: <chris-curl_at_cybermato.com>
Date: Sat, 26 Dec 2009 11:25:49 -0800

Hello. I have made good use of both curl and libcurl for many purposes
lately; thank you very much for the excellent tool!

I would like to respectfully suggest that the documentation of the various
options be more explicit about the interaction between various options. In
particular, I spent many hours debugging why the following code (to "clear"
the state of an easy handle I had used for a PUT, prior to recycling it for
use in a GET) did not have the desired effect, and libcurl kept insisting on
doing a PUT instead of the GET I was trying to request:

    curl_easy_setopt (ceh, CURLOPT_UPLOAD, 0);
    curl_easy_setopt (ceh, CURLOPT_HTTPGET, 1);
    curl_easy_setopt (ceh, CURLOPT_POSTFIELDS, NULL);
    curl_easy_setopt (ceh, CURLOPT_POSTFIELDSIZE, -1);

Finally resorting to reading the source, I quickly determined (with the help
of the very clear comment on this matter in lib/url.c) that setting
POSTFIELDS - even to NULL!!! - will force the handle into PUT state
(essentially as if I set HTTPPUT and/or UPLOAD to 1). So, changing the code
to the following, my program then worked just as expected:

    curl_easy_setopt (ceh, CURLOPT_POSTFIELDS, NULL);
    curl_easy_setopt (ceh, CURLOPT_POSTFIELDSIZE, -1);
    curl_easy_setopt (ceh, CURLOPT_UPLOAD, 0);
    curl_easy_setopt (ceh, CURLOPT_HTTPGET, 1);

So it seems that it would be quite valuable if the documentation were as clear
as the source comment is about the side-effects of setting POSTFIELDS. And
as there are a few other similar side-effects to setting other options, it
would be helpful to document those as well.

Many thanks,
     Chris MacGregor
     Seattle, Washington State, USA
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-12-26