'When creating a cookie for the response, a safe_cookie_data
is created and put in place of the session_id in the session
cookie.
Also, the session cookie is deleted if prior verification failed
or the designated user in the request has changed since the
original request.
Processing the response is a multi-step process, as follows:
Step 1. Call the parent\'s method to generate the basic cookie.
Step 2. Verify that the user marked at the time of
process_request matches the user at this time when processing
the response.  If not, log the error.
Step 3. If a cookie is being sent with the response, update
the cookie by replacing its session_id with a safe_cookie_data
that binds the session and its corresponding user.
Step 4. Delete the cookie, if it\'s marked for deletion.'

def process_response(self, request, response):

    response = super(SafeSessionMiddleware, self).process_response(request, response)
    if ((not _is_cookie_marked_for_deletion(request)) and _is_cookie_present(response)):
        try:
            user_id_in_session = self.get_user_id_from_session(request)
            with controlled_logging(request, log):
                self._verify_user(request, user_id_in_session)
                self.update_with_safe_session_cookie(response.cookies, user_id_in_session)
        except SafeCookieError:
            _mark_cookie_for_deletion(request)
    if _is_cookie_marked_for_deletion(request):
        _delete_cookie(response)
    return response
