beppu / anyevent-couchdb

a non-blocking CouchDB client for Perl based on jquery.couch.js
http://github.com/beppu/anyevent-couchdb/tree/master
19 stars 6 forks source link

Handle GET with open_revs #4

Open OrangeDog opened 13 years ago

OrangeDog commented 13 years ago

At the moment you can do the following, which will not work as the JSON parser is given the raw multi-part response.

$db->open_doc($id, {'open_revs' => 'all'})->recv;

Presumably this should return an array of all the versions (and probably ignore any attachments in the response).

beppu commented 13 years ago

I was unable to replicate this bug, because CouchDB sent me parseable JSON when I tried this. I'm curious to see what kind of response you're getting from CouchDB, so could you use curl to make a similar request, and paste the response that CouchDB gives you, please?

curl 'http://localhost:5984/test/da173e45950d5a80a20b54600c000fd1?open_revs=all'

^Do something like that w/ the db and id replaced to fit your database and paste the result here.

OrangeDog commented 13 years ago

From couchdb-1.1.0+COUCHDB-1152 OTP/R14B01+OTP-9139 Win32

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Server: CouchDB/1.1.0 (Erlang OTP/R14B01)
Date: Tue, 06 Sep 2011 08:51:15 GMT
Content-Type: multipart/mixed; boundary="3c39738dd1c940813b235430c88cc542"

--3c39738dd1c940813b235430c88cc542
Content-Type: application/json

{/* JSON for head revision */}
--3c39738dd1c940813b235430c88cc542
Content-Type: application/json

{/* JSON for a deleted conflict */}
--3c39738dd1c940813b235430c88cc542--

When there are attachments, the attachment stub has "follows": true and there is an additional (untyped) part containing the unencoded data for each attachment.

beppu commented 13 years ago

Thanks. I'm going to try to make some conflicts happen in my db to try to make it send me a multipart/mixed response.

OrangeDog commented 13 years ago

I think it's only with version 1.1 that it's started doing it: 1.0.3 just returns a JSON array.

beppu commented 13 years ago

That's good to know. I'll try to accomodate both if I can.