Jakob Hirsch | 5 Jul 2012 11:40
Picon
Gravatar

no output wanted (resend)

Hi,

is there a simple way to make curl_easy_perform() not to output any
data? I just want to HTTP-POST something to a web interface and are not
interested in the server's reply.

I first thought maybe setting CURLOPT_WRITEDATA to NULL could do the
trick, but then libcurl simply segfaults (for obvious reasons).
Setting CURLOPT_NOBODY also does not work, it seems to force the use of
HEAD, regardless if set CURLOPT_HTTPPOST before or after it. (Even
though the spec says "When setting CURLOPT_HTTPPOST, it will
automatically set CURLOPT_NOBODY to 0 (since 7.14.1)." and I'm using
7.26.0, but that's a different story.)

Right now I help myself by using a dummy function with
CURLOPT_WRITEFUNCTION that just returns size*nmemb to make libcurl
happy. That's work fine, but it seems to me quite cumbersome (and a
waste of resources, albeit a small one).

Anything I missed?

Regards,
Jakob
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Daniel Stenberg | 5 Jul 2012 16:12
Picon
Favicon
Gravatar

Re: no output wanted (resend)

On Thu, 5 Jul 2012, Jakob Hirsch wrote:

> is there a simple way to make curl_easy_perform() not to output any data? I 
> just want to HTTP-POST something to a web interface and are not interested 
> in the server's reply.

I read that as you want to stop receiving data and not just not output it?

Then I'd suggest you return an error from the write callback instead of just 
silently discarding the received data as then libcurl will immediately fail 
and bail out without waiting for more data to arrive.

--

-- 

  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Jakob Hirsch | 5 Jul 2012 18:26
Picon
Gravatar

Re: no output wanted (resend)

Daniel Stenberg, 05.07.2012 16:12:
>> is there a simple way to make curl_easy_perform() not to output any
>> data? I just want to HTTP-POST something to a web interface and are
>> not interested in the server's reply.
> I read that as you want to stop receiving data and not just not output it?

Oh, no, I do want to receive the server's reply (or at least the HTTP
code), I just don't want curl output the data on the console (stdout or
stderr). The server's reply is only a single line, so there's no harm in
reading that from the network.

If there's currently no simple way to do that, may I propose that make
that possible? E.g. by calling the write function only if it is set to a
custom func or the file handle being not NULL. As far as I see the write
function is only called at one place, so that should be fairly simple.
The attached patch does just that (untested, though).

Attachment (noout.diff): text/x-patch, 522 bytes
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Daniel Stenberg | 5 Jul 2012 19:27
Picon
Favicon
Gravatar

Re: no output wanted (resend)

On Thu, 5 Jul 2012, Jakob Hirsch wrote:

> Oh, no, I do want to receive the server's reply (or at least the HTTP code), 
> I just don't want curl output the data on the console (stdout or stderr). 
> The server's reply is only a single line, so there's no harm in reading that 
> from the network.

But shouldn't you then use the write callback to receive the data?

> If there's currently no simple way to do that, may I propose that make that 
> possible? E.g. by calling the write function only if it is set to a custom 
> func or the file handle being not NULL.

Sorry, I must be missing something here. What would be the point of that?

--

-- 

  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Jakob Hirsch | 8 Jul 2012 14:24
Picon
Gravatar

Re: no output wanted (resend)

On 05.07.2012 19:27, Daniel Stenberg wrote:
>> Oh, no, I do want to receive the server's reply (or at least the HTTP
>> code), I just don't want curl output the data on the console (stdout
>> or stderr). The server's reply is only a single line, so there's no
>> harm in reading that from the network.
> But shouldn't you then use the write callback to receive the data?

Why use a callback function when I don't need the reply. I just want
libcurl to discard the data.

>> If there's currently no simple way to do that, may I propose that make
>> that possible? E.g. by calling the write function only if it is set to
>> a custom func or the file handle being not NULL.
> Sorry, I must be missing something here. What would be the point of that?

It seems that I created some confusion. Sorry for that.
It's really not a big deal. As I wrote: All I want to do is to let
libcurl perform a HTTP POST, discard the server's reply (the data, not
the response code of course, which I get with CURLINFO_RESPONSE_CODE). I
just thought that it might be a good idea to support that inside of
libcurl. So instead of using a dummy callback function like here:

size_t curl_devnull(char *ptr, size_t size, size_t nmemb, void *userdata) {
        return size * nmemb;
}

int main
{
...

(Continue reading)

Daniel Stenberg | 8 Jul 2012 14:29
Picon
Favicon
Gravatar

Re: no output wanted (resend)

On Sun, 8 Jul 2012, Jakob Hirsch wrote:

>>> If there's currently no simple way to do that, may I propose that make
>>> that possible? E.g. by calling the write function only if it is set to
>>> a custom func or the file handle being not NULL.
>> Sorry, I must be missing something here. What would be the point of that?
>
> It seems that I created some confusion. Sorry for that. It's really not a 
> big deal. As I wrote: All I want to do is to let libcurl perform a HTTP 
> POST, discard the server's reply (the data, not the response code of course, 
> which I get with CURLINFO_RESPONSE_CODE). I just thought that it might be a 
> good idea to support that inside of libcurl.

Okay, I understand now! =)

Well, I don't think your idea here is bad but I'm bit reluctant to change 
details in this area as I am convinced there are existing applications in the 
wild that set things to NULL in various combinations already to get the 
functionality of existing libcurl. So keeping the existing ABI is more 
important than introducing a very small short-cut to future applications I 
think...

--

-- 

  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

(Continue reading)

Joe Mason | 8 Jul 2012 20:29
Favicon
Gravatar

RE: no output wanted (resend)

> From: curl-library-bounces <at> cool.haxx.se [curl-library-bounces <at> cool.haxx.se] on
>  behalf of Daniel Stenberg [daniel <at> haxx.se]
> Sent: Sunday, July 08, 2012 8:29 AM
> To: libcurl development
> Subject: Re: no output wanted (resend)
> 
> Well, I don't think your idea here is bad but I'm bit reluctant to change
> details in this area as I am convinced there are existing applications in the
> wild that set things to NULL in various combinations already to get the
> functionality of existing libcurl. So keeping the existing ABI is more
> important than introducing a very small short-cut to future applications I
> think...

If I'm reading this right, currently if you set CURLOPT_WRITEDATA to NULL without setting
CURLOPT_WRITEFUNCTION, curl crashes.  How can an existing app be depending on that?

Joe
---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged
material (including material protected by the solicitor-client or other applicable privileges), or
constitute non-public information. Any use of this information by anyone other than the intended
recipient is prohibited. If you have received this transmission in error, please immediately reply to
the sender and delete this information from your system. Use, dissemination, distribution, or
reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

(Continue reading)

Daniel Stenberg | 8 Jul 2012 22:44
Picon
Favicon
Gravatar

RE: no output wanted (resend)

On Sun, 8 Jul 2012, Joe Mason wrote:

>> Well, I don't think your idea here is bad but I'm bit reluctant to change 
>> details in this area as I am convinced there are existing applications in 
>> the wild that set things to NULL in various combinations already to get the 
>> functionality of existing libcurl. So keeping the existing ABI is more 
>> important than introducing a very small short-cut to future applications I 
>> think...
>
> If I'm reading this right, currently if you set CURLOPT_WRITEDATA to NULL 
> without setting CURLOPT_WRITEFUNCTION, curl crashes.  How can an existing 
> app be depending on that?

Heh, yeah that struck me as well after I sent that mail... I clearly didn't 
think that through all the way! =)

The question is if we want to make CURLOPT_WRITEDATA set to NULL with 
CURLOPT_WRITEFUNCTION unset or set to NULL equal a callback that just return 
the number of bytes it gets. As we can clearly do that without breaking 
anything, as doing that with a current libcurl will just get you a crash...

It seems like a very small use case for another special case in the code that 
isn't very easy guessable. Or what do others think? Am I just being grumpy?

--

-- 

  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
(Continue reading)

Jakob Hirsch | 9 Jul 2012 01:06
Picon
Gravatar

Re: no output wanted (resend)

On 08.07.2012 22:44, Daniel Stenberg wrote:
> The question is if we want to make CURLOPT_WRITEDATA set to NULL with
> CURLOPT_WRITEFUNCTION unset or set to NULL equal a callback that just
> return the number of bytes it gets. As we can clearly do that without

The only good reason I can think of to make it _not_ functionally
equivalent is that it could hide errors when somebody is playing around
with the file handle and erroneously sets it to NULL. But then again
this person could appreciate that this prevents his application from
crashing.

> It seems like a very small use case for another special case in the code
> that isn't very easy guessable. Or what do others think? Am I just being

I'm a little surprised that nobody wanted this before. Using libcurl to
call some web interface (and not caring about the reply data when using
something different than GET) seemed self-evident to me...
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Daniel Stenberg | 9 Jul 2012 16:22
Picon
Favicon
Gravatar

Re: no output wanted (resend)

On Mon, 9 Jul 2012, Jakob Hirsch wrote:

> I'm a little surprised that nobody wanted this before. Using libcurl to call 
> some web interface (and not caring about the reply data when using something 
> different than GET) seemed self-evident to me...

Sure, but providing a one-line function that does a return of the value it 
gets passed in probably wasn't considered a big deal to talk about for those 
who wanted to ignore the response...

--

-- 

  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html


Gmane