igrigorik/em-http-request — pull request #269 by turley (2014-05-02 04:33:41+00:00)
Title: Fix gzip decompression in cases where first bytes arrive slowly

I've noticed intermittent errors with gzip-encoded responses when communicating with web services that support gzip.

After some investigation, I found in certain cases (e.g., when the first few bytes arrive individually at the decoder, followed by the remainder of the body), gzip-encoded response bodies are causing the GZip decoder to raise a DecoderError (really a Zlib::DataError).

For an example that illustrates the breaking behavior (when run against the current implementation), refer to the included "should decompress a vanilla gzip file from various-sized chunks" test.

By removing the custom GZipHeader implementation, I get consistently correct results regardless of how the data arrives. I'm not entirely sure why the custom gzip header extraction was ever needed since zlib appears capable of handling the header itself. If someone can provide a test case showing the need for GZipHeader, please let me know. Otherwise, it appears unnecessary (and problematic in this case).