def METHOD_NAME(request, response):
    if request.path.startswith('/api'):
        return
    pub_key_name = settings.SESSION_RSA_PUBLIC_KEY_NAME
    public_key = request.session.get(pub_key_name)
    cookie_key = request.COOKIES.get(pub_key_name)
    if public_key and public_key == cookie_key:
        return
    pri_key_name = settings.SESSION_RSA_PRIVATE_KEY_NAME
    private_key, public_key = gen_key_pair()
    public_key_decode = base64.b64encode(public_key.encode()).decode()
    request.session[pub_key_name] = public_key_decode
    request.session[pri_key_name] = private_key
    response.set_cookie(pub_key_name, public_key_decode)