'Called prior to requests being sent.
:param request: Request to be sent
:return: returns the original request, registering hooks on the response if it is the first time this url has been called and an
auth challenge might be returned'

def __call__(self, request):

    if self._callback:
        challenge = ChallengeCache.get_challenge_for_url(request.url)
        if challenge:
            self.set_authorization_header(request, challenge)
        else:
            try:
                self._thread_local.pos = request.body.tell()
            except AttributeError:
                self._thread_local.pos = None
            self._thread_local.auth_attempted = False
            request.register_hook('response', self.handle_401)
            request.register_hook('response', self.handle_redirect)
    return request
