Fix Gzip encoding support

Make sure that the response code is recorded when Gzip is enabled.
Add unit test.