basho/webmachine — pull request #118 by reiddraper (2013-01-29 21:22:51+00:00)
Title: Wrd content length with streaming rebased 1

Currently streaming responses of the form `{stream, streambody()}` must be exhausted in order to determine the `Content-Length`. There are good reasons for this (the body may be processed by some content-encoding), but sometimes you want to just say, "hey webmachine, I _know_ the `Content-Length` and here it is". This is useful if you have large resources and don't want the response returned with `Transfer-Encoding: chunked`. This is also useful when you want to allow HEAD requests to return a `Content-Length` without having to exhaust a large stream. This patch adds a new stream type, `known_length_stream`, whose values look like:

```erlang
-type known_length_stream() :: {known_length_stream, ContentLength :: non_neg_integer(), streambody()}
```

While this code has been used in Riak CS for the past year or so, I'm quite open to feedback on approaches to make this more general, etc.