couchrest/couchrest — pull request #98 by frasertweedale (2013-05-25 09:42:55+00:00)
Title: Streamer: correctly handle continuous feeds

When querying _changes API with feed=continuous, the first output
row is always discarded. Implement the following heuristic to
correctly deal with continuous feeds:

1) If the line ends with "[", it is a header. Do not yield it.
2) Parse the line. If the row has a "rows" or "results" key, it
is a complete header (either from view or changes API). Do not
yield it.
3) There is no header. Yield the row.

Return ``nil`` if the continuous feed ends since there is no header.

Step 2) contains some CouchDB API-specific knowledge; this is
unfortunate. One approach to remove this knowledge would be to
parameterise the ``get`` and ``post`` methods with a key to look for
to determine if the first line is a complete header (i.e. no result
rows), or if it is a result row (i.e. no header, as in a continuous
feed). However, this commit sacrifices such purity to keep the
change small and the risk low.

Spec for continuous feed behaviour is included.