'Check the headers if the client accepts gzip encoding, and encodes the
request if so.'

def encoderForRequest(self, request):

    acceptHeaders = request.requestHeaders.getRawHeaders('accept-encoding', [])
    supported = ','.join(acceptHeaders).split(',')
    if ('gzip' in supported):
        encoding = request.responseHeaders.getRawHeaders('content-encoding')
        if encoding:
            encoding = ('%s,gzip' % ','.join(encoding))
        else:
            encoding = 'gzip'
        request.responseHeaders.setRawHeaders('content-encoding', [encoding])
        return _GzipEncoder(self.compressLevel, request)
