ring-clojure/ring — pull request #115 by llasram (2014-01-03 20:17:55+00:00)
Title: Enumerate collection response `:body`s via `reduce`.

In Clojure 1.5+, the `CollReduce` protocol provides a more flexible definition of a "collection" than `ISeq`. In particular in the context of generating streaming chunked-encoded HTTP responses, `CollReduce` implementations may have lexically-scoped `finally`-style resource clean-up code.

Modiying the ring servlet adapter to use `CollReduce` instead of `ISeq` when available, then process the body via `reduce` instead of `doseq` should provide these benefits in an entirely backwards-compatible fashion.

This PR somewhat orthogonally fixes what I believe to be a bug in the current support for `ISeq` bodies. Apparently `PrintWriter` instances never throw exceptions after construction, so e.g. a client closing a connection before completely recieving a chunked-encoded response would leave the `doseq` continuing to iterate until it had exhausted the body seq. The `.checkError` method acts a `.flush`, but also reports if an error has occurred, allowing the adapter to throw an exception.