CurtTilmes / raku-libcurl

A Raku interface to libcurl.
Other
19 stars 9 forks source link

WRITEFUNCTION #18

Open pprocacci opened 4 years ago

pprocacci commented 4 years ago

It's be nice if this (and perhaps the corresponding READFUNCTION libcurl options were made available to the end user.

I've got an application sending chunked responses which does so upon events occuring on the server. The connection is kept-alive and data arrives from every 1 second, to maybe never. The connection never gets torn down.

This module lacks the ability to receive these partial messages and it appears it just buffers them until a full response is received. Being able to set my own handler would be kinda nice.

If this option exists, I apologize in advance. I looked through the source code and was unable to find anything that would indicate a function pointer exists for such a thing. (There is a call to CURLOPT_WRITEFUNCTION but it's hard-coded pointing to a sub).

CurtTilmes commented 4 years ago

I played around with this a long time ago, but never got it to a state I really like.

Instead of using callbacks, I wanted to use a Raku Channel to stream the data.

You can try the not quite prime-time work like this:

my $curl = LibCurl::Easy.new(URL => ...);

my $stream = $curl.stream-out;

start react whenever $stream -> $in {
        say "in: ", $in;
}

$curl.perform;