def _handleRedirect(self, response, method, uri, headers, redirectCount):
        """
        Handle a redirect response, checking the number of redirects already
        followed, and extracting the location header fields.
        """
        if redirectCount >= self._redirectLimit:
            err = error.InfiniteRedirection(
                response.code,
                'Infinite redirection detected',
                location=uri)
            raise ResponseFailed([failure.Failure(err)], response)
        locationHeaders = response.headers.getRawHeaders('location', [])
        if not locationHeaders:
            err = error.RedirectWithNoLocation(
                response.code, 'No location header field', uri)
            raise ResponseFailed([failure.Failure(err)], response)
        location = locationHeaders[0]
        deferred = self._agent.request(method, location, headers)
        return deferred.addCallback(
            self._handleResponse, method, uri, headers, redirectCount + 1)
dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/web/client.py/RedirectAgent._handleRedirect/original