[drakma-devel] Handling chunked content

Edi Weitz edi at agharta.de
Thu Jun 5 01:26:45 UTC 2008


On Thu, 5 Jun 2008 02:43:48 +0200, "Nico Garcia Belmonte" <philogb at gmail.com> wrote:

> ...I'm kind of a newbie, so please forgive me if I make stupid
> questions.  I've been using drakma to request html pages and
> everything seems to work fine.
>
> I'm now using drakma to make a request to the new youtube json api,
> and I get chunked content:
>
> (http-request "
> http://gdata.youtube.com/feeds/api/videos/-/Music/?max-results=10&vq=bush&alt=json&format=5
> ")
>
> ...chunked content...
>
> ((:CONTENT-TYPE . "application/json; charset=UTF-8")
>  (:CACHE-CONTROL . "max-age=0, must-revalidate, no-transform, private")
>  (:GDATA-VERSION . "1.0") (:LAST-MODIFIED . "Thu, 05 Jun 2008 00:20:27 GMT")
>  (:TRANSFER-ENCODING . "chunked") (:DATE . "Thu, 05 Jun 2008 00:20:27 GMT")
>  (:SERVER . "GFE/1.3") (:CONNECTION . "Close"))
> #<PURI:URI
> http://gdata.youtube.com/feeds/api/videos/-/Music/?max-results=10&vq=bush&alt=json&format=5
>>
> #<FLEXI-STREAMS:FLEXI-IO-STREAM {B90E249}>
>
> The thing is that I need it to be a string in order to decode to
> json format using the cl-json lisp package.  I tried changing the
> external-output parameter without any good results.
>
> Do you have some advice on how I could serialize this content?

Your problem is not chunked content (Drakma takes care of that
automatically) but that the server returns a content type which is by
default not recognized as text.  See for example here:

  http://weitz.de/drakma/#*text-content-types*
  http://weitz.de/drakma/#*body-format-function*

In your particular case, something like this will probably do the
trick:

  (let ((*text-content-types* (cons '("application" . "json")
                                    *text-content-types*)))
    (http-request "http://gdata.youtube.com/feeds/api/videos/-/Music/?max-results=10&vq=bush&alt=json&format=5"))

Cheers,
Edi.



More information about the Drakma-devel mailing list