playframework/Play20 — pull request #661 by jroper (2013-01-09 08:57:26+00:00)
Title: Added support for handling trailing headers to WS API

There is a quite serious bug in our WS streaming implementation, where if the server sends trailing headers at the end of a chunked response (eg, a common would be the MD5 header), the WS API will create a new iteratee, by invoking the consume method again, losing the old one that parsed the body.

This not only fixes that bug, it adds a callback that allows you to handle those headers. The callback accepts both the headers, and the iteratee, and returns an iteratee, so for example if handling the MD5 header, assuming you were using an iteratee that md5s the content as it arrives, you could map the result of the iteratee to validate the MD5 and produce either an error or the original result.

In order to maintain backward compatibility, new methods with new names were introduced. I initially wanted to just use a second parameter with a default argument, but that breaks code that was passing a single function argument without braces. Overloading didn't work either, scalac complained about ambiguity.