Curl wrapper round two

jdrewsen jdrewsen at nospam.com
Sun Jun 19 11:48:44 PDT 2011


Den 19-06-2011 17:43, Johannes Pfau skrev:
> jdrewsen wrote:
>> Den 19-06-2011 11:08, Johannes Pfau skrev:
>>> jdrewsen wrote:
>>>> Hi,
>>>>
>>>>      I've finally got through all the very constructive comments from
>>>> the
>>>> last review of the curl wrapper and performed the needed changes.
>>>>
>>>> Here is the github branch:
>>>> https://github.com/jcd/phobos/tree/curl-wrapper
>>>>
>>>> And the generated docs:
>>>> http://freeze.steamwinter.com/D/web/phobos/etc_curl.html
>>>>
>>>> I do have some problems getting ddoc to show the documentation of
>>>> mixins. So in order to view the doc for byLine/byChunk methods you
>>>> have to look at the source.
>>>
>>> That's bad because lots of useful stuff hides in the protocol mixin.
>>> The url property for example is essential for keep-alive requests,
>>> but it doesn't show up in the documentation :-(
>>
>> I agree. And also in the ByLineAsync etc. mixins. I would very much
>> like to get a hint on how to do it if anyone knows.
>>
>>> Also, a keep alive example would be great:
>>> --------------------------------------------
>>> auto client =
>>> Http("http://api.vevo.com/mobile/v2/authentication.json");
>>> client.addHeader("User-Agent", "Android API Connector");
>>> client.addHeader("Connection", "Keep-Alive"); client.method =
>>> Http.Method.post; client.onReceive = (ubyte[] data)
>>> { write(cast(char[])data); return data.length; };
>>> client.postData = "p=android&v=1.05";
>>> client.perform();
>>>
>>> //2nd request
>>> client.url = "http://api.vevo.com/mobile/v1/featured/carousel.json";
>>> client.method = Http.Method.get;
>>> client.perform();
>>> --------------------------------------------
>>> Maybe something like this. (+points if the code uses existing
>>> websites)
>>
>> I'll include that.
> Feel free to use this example, but please note that the vevo api is not
> public, so it could break any time.
>
>> And I need a "header(key, value)" parameter on
>> Http.(Async)Result as well. That way your example could be written:
>>
>> auto r = Http.post("http://api.vevo.com/mobile/v2/authentication.json",
>>                     "p=android&v=1.05")
>>                     .header("User-Agent", "Android API Connector")
>>                     .header("Connection", "Keep-Alive"));
>> write(r.bytes);
>
> Looks great, but I guess it won't help for keep-alive sessions? Or is
> it possible to reuse the Curl client with the static methods?

Not in the linked version. But is it a nice idea that I'm working on now.

> I also found another small problem related to keep-alive:
> How can I change a header that's been added with addHeader? I have to
> reuse the client to use keep-alive, however calling addHeader with the
> same key again just appends the header, but it doesn't replace it. An
> easy solution is to expose a clearHeader function, but this means if the
> user wants to change 1 header all other headers must be set
> again. It seems the curl api is too limited to do something more
> advanced though. Having a D associative array for the headers might be
> possible, but then it has to be converted for curl in every request.

I'm actually storing a curl_slist to keep the headers. This makes it 
possible to manipulate the headers as you request. I'll fix it so that 
you can change and remove individual headers.


>>> BTW: The curl verbose output is great. I guess it won't
>>> be activated in phobos by default, but is it possible to activate it
>>> manually? If so, this very useful feature should be documented.
>>
>> Yes - verbose should be made in a property by itself.
>>
>> Thank you for the comments!
>> /Jonas
>>
> You're welcome!
>



More information about the Digitalmars-d mailing list