There is a fairly serious problem at the moment with using list
functions in CouchDB.
To recap, the view server line protocol for _list functions looks like this.
>>> ["lists", "name", {request}]
<<< ["start", ["chunks"], {"headers":{}, "code":200}]
>>> ["list_row", {"key":"k","value":"v"}]
<<< ["chunk", ["chunks"]]
>>> ["list_end"]
<<< ["end", ["tail chunks"]]
The problem with this is that the response from the view server that
contains the status code MUST come before any list_row calls have
happened. This means that the view server can't return 404 for queries
that don't have any results. In fact, the view can really only return
200 for anything but a HEAD request on list functions.
I'd like to propose the following changes to the view server protocol
for list functions.
>>> ["lists", "name"]
<<< ["getRow"]
>>> ["list_row", {"key":"k","value":"v"}]
<<< ["getRow"]
>>> ["list_row", {"key":"k","value":"v"}]
<<< ["start", "chunk", {"headers":{}, "code":200}]
<<< ["send", "chunk"]
<<< ["send", "chunk"]
<<< ["getRow"]
>>> ["list_row", {"key":"k","value":"v"}]
<<< ["getRow"]
>>> ["list_end"]
<<< ["end", "tail chunk"]
The big change is that there is no longer a strict request/response.
The erlang side stays idle accepting chunks to send until it gets a
["getRow"] call.
Also, all chunks sent in a single line to erlang get sent to the
client in one chunk anyway so I changed the type from array to string
since you can do multiple ["send"] calls between ["list_row"]
responses anyway.
Thoughts?
-Mikeal