curl-and-python

Re: Curl Object - unset range option

From: Michael Wood <esiotrot_at_gmail.com>
Date: Wed, 13 Jul 2011 09:29:05 +0200

Hi

On 13 July 2011 09:24, Michael Wood <esiotrot_at_gmail.com> wrote:
> On 13 July 2011 01:05, Konstantinos Botsaris <cosbots_at_gmail.com> wrote:
>>
>> On 12 Jul 2011, at 22:39, Daniel Stenberg wrote:
>>
>>> On Tue, 12 Jul 2011, Konstantinos Botsaris wrote:
>>>
>>>>>> I would like to ask if there is a way to unset the header option which was previously set
>>>
>>>>> You probably need to check the pycurl code so that 'None' truly equals setting the underlying option to NULL.
>>>>
>>>> Can you be a little bit more specific of what exactly I should do ? Thanks
>>>
>>> Custom headers are possible to "unset" when using the plain C API. You probably need to make sure that the python binding is doing it the proper way.
>>>
>>> --
>>>
>>> / daniel.haxx.se
>>> _______________________________________________
>>> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
>>
>> Ok I will try that  Daniel. Thanks again!
>
> In src/pycurl.c there is the following line:
>
> static char co_unsetopt_doc [] = "unsetopt(option) -> None.  Reset
> curl session option to default value.  Throws pycurl.error exception
> upon failure.\n";
>
> So perhaps you could try c.unsetopt(...) instead of c.setopt(..., None).

I've just checked the definition of unsetopt and it only works for
certain options:

    /* FIXME: implement more options. Have to carefully check lib/url.c in the
     * libcurl source code to see if it's actually safe to simply
     * unset the option. */
    switch (option)
    {
    case CURLOPT_SHARE:
        SETOPT((long)0);
        Py_XDECREF(self->share);
        self->share = NULL;
        break;
    case CURLOPT_HTTPPOST:
        SETOPT((void *) 0);
        curl_formfree(self->httppost);
        self->httppost = NULL;
        /* FIXME: what about data->set.httpreq ?? */
        break;
    case CURLOPT_INFILESIZE:
        SETOPT((long) -1);
        break;
    case CURLOPT_WRITEHEADER:
        SETOPT((void *) 0);
        ZAP(self->writeheader_fp);
        break;
    case CURLOPT_CAINFO:
    case CURLOPT_CAPATH:
    case CURLOPT_COOKIE:
    case CURLOPT_COOKIEJAR:
    case CURLOPT_CUSTOMREQUEST:
    case CURLOPT_EGDSOCKET:
    case CURLOPT_FTPPORT:
    case CURLOPT_PROXYUSERPWD:
    case CURLOPT_RANDOM_FILE:
    case CURLOPT_SSL_CIPHER_LIST:
    case CURLOPT_USERPWD:
        SETOPT((char *) 0);
        break;

    /* info: we explicitly list unsupported options here */
    case CURLOPT_COOKIEFILE:
    default:
        PyErr_SetString(PyExc_TypeError, "unsetopt() is not supported
for this option");
        return NULL;
    }

-- 
Michael Wood <esiotrot_at_gmail.com>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2011-07-13