sandstorm-io/sandstorm — pull request #191 by dwrensha (2014-12-20 19:19:48+00:00)
Title: use chunked encoding for upload streams of unknown length; use refcounted stream

I was seeing errors when git made large POST requests using `Transfer-Encoding: chunked`.

In its current form, `sandstorm-http-bridge` forwards these requests with neither the Content-Length nor the Transfer-Encoding header set -- instead it indicates the end of the content by calling `shutdownWrite()`. Unfortunately, this scheme does not seem to be recognized by the servers in my apps; they truncate such requests and return early, which causes further problems when `RequestStreamImpl`'s `stream` gets written to after it gets moved into the `HttpParser`, triggering a segfault.

This patch implements chunked transfer encoding and prevents early responses from causing problems.

I think git is our first client to test this code path at all. I think that all of our other apps that use streaming requests always set the Content-Length. I have verified that large uploads in Groove Basin still work after this change.