koajs/koa — pull request #113 by jonathanong (2013-12-09 10:21:48+00:00)
Title: res.body handles errors of all streams ever set

as discussed in #111, stream handling is now done every time you set `this.body = stream`. this means you should never have to do `stream.on('error', this.onerror)` anymore. also, references are cleaned up when the stream is "done" to avoid any leaks.

it should be fine when replacing streams that depend on each other (i.e. replacing a stream with a compressed stream). might get into trouble if users completely change bodies that are not dependent upon each other. only scenario that we should support are custom error pages when a stream errors - but as #111 demonstrated, that's not even possible right now.