Fix Content-Encoding header on gzip responses

Currently the header is written before Content-Encoding is set; this fixes that.