'Check if the response is encoded, and wrap it to handle decompression.'

def _handleResponse(self, response):

    contentEncodingHeaders = response.headers.getRawHeaders('content-encoding', [])
    contentEncodingHeaders = ','.join(contentEncodingHeaders).split(',')
    while contentEncodingHeaders:
        name = contentEncodingHeaders.pop().strip()
        decoder = self._decoders.get(name)
        if (decoder is not None):
            response = decoder(response)
        else:
            contentEncodingHeaders.append(name)
            break
    if contentEncodingHeaders:
        response.headers.setRawHeaders('content-encoding', [','.join(contentEncodingHeaders)])
    else:
        response.headers.removeHeader('content-encoding')
    return response
