'If the response has a C{gzip} I{Content-Encoding} header,
L{GzipDecoder} wraps the response to return uncompressed data to the
user.'

def test_gzipEncodingResponse(self):

    deferred = self.agent.request('GET', 'http://example.com/foo')
    (req, res) = self.protocol.requests.pop()
    headers = http_headers.Headers({'foo': ['bar'], 'content-encoding': ['gzip']})
    transport = StringTransport()
    response = Response(('HTTP', 1, 1), 200, 'OK', headers, transport)
    response.length = 12
    res.callback(response)
    compressor = zlib.compressobj(2, zlib.DEFLATED, (16 + zlib.MAX_WBITS))
    data = ((compressor.compress(('x' * 6)) + compressor.compress(('y' * 4))) + compressor.flush())
    def checkResponse(result):
        self.assertNotIdentical(result, response)
        self.assertEqual(result.version, ('HTTP', 1, 1))
        self.assertEqual(result.code, 200)
        self.assertEqual(result.phrase, 'OK')
        self.assertEqual(list(result.headers.getAllRawHeaders()), [('Foo', ['bar'])])
        self.assertEqual(result.length, UNKNOWN_LENGTH)
        self.assertRaises(AttributeError, getattr, result, 'unknown')
        response._bodyDataReceived(data[:5])
        response._bodyDataReceived(data[5:])
        response._bodyDataFinished()
        protocol = SimpleAgentProtocol()
        result.deliverBody(protocol)
        self.assertEqual(protocol.received, [(('x' * 6) + ('y' * 4))])
        return defer.gatherResults([protocol.made, protocol.finished])
    deferred.addCallback(checkResponse)
    return deferred
