def encoderForRequest(self, request):
        """
        Check the headers if the client accepts gzip encoding, and encodes the
        request if so.
        """
        acceptHeaders = b','.join(
            request.requestHeaders.getRawHeaders(b'accept-encoding', []))
        if self._gzipCheckRegex.search(acceptHeaders):
            encoding = request.responseHeaders.getRawHeaders(
                b'content-encoding')
            if encoding:
                encoding = b','.join(encoding + [b'gzip'])
            else:
                encoding = b'gzip'

            request.responseHeaders.setRawHeaders(b'content-encoding',
                                                  [encoding])
            return _GzipEncoder(self.compressLevel, request)

        Check the headers if the client accepts gzip encoding, and encodes the
        request if so.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/server.py