'Handle encodings in the order that they are encountered.'

def http_response(self, req, resp):

    encodings = []
    headers = resp.headers
    encoding_header = None
    for header in headers:
        if (header.lower() == 'content-encoding'):
            encoding_header = header
            for encoding in headers[header].split(','):
                encoding = encoding.strip()
                if encoding:
                    encodings.append(encoding)
            break
    if (not encodings):
        return resp
    del headers[encoding_header]
    fp = resp
    while (encodings and (encodings[(-1)].lower() == 'gzip')):
        fp = cStringIO.StringIO(fp.read())
        fp = gzip.GzipFile(fileobj=fp, mode='r')
        encodings.pop()
    if encodings:
        headers[encoding_header] = ',    '.join(encodings)
        logger.warning('Unrecognized    Content-Encoding:    %s', encodings[(-1)])
    msg = resp.msg
    if (sys.version_info >= (2, 6)):
        resp = urllib2.addinfourl(fp, headers, resp.url, resp.code)
    else:
        response_code = resp.code
        resp = urllib2.addinfourl(fp, headers, resp.url)
        resp.code = response_code
    resp.msg = msg
    return resp
