Example #1
0
def set_language_cookie(request: Request, response: Response,
                        lang: Optional[str]) -> None:
    cookie_lang = request.cookie("language")
    if cookie_lang == lang:
        return

    if lang is None:
        del_language_cookie(response)
    else:
        response.set_http_cookie("language", lang, secure=request.is_secure)
Example #2
0
def is_mobile(request: Request, response: Response) -> bool:
    if request.has_var("mobile"):
        mobile = bool(request.var("mobile"))
        # Persist the explicitly set state in a cookie to have it maintained through further requests
        response.set_http_cookie("mobile", str(int(mobile)), secure=request.is_secure)
        return mobile

    if request.has_cookie("mobile"):
        return request.cookie("mobile", "0") == "1"

    return _is_mobile_client(request.user_agent.string)