a c@sddlZddlZddlZddlmZmZddlZddlmZddl m Z m Z ddl m Z ddlmZmZmZmZmZejdkrddlmZn ddlmZGd d d ZdS) N) b64decode b64encode) BadSignature)MutableHeadersSecret)HTTPConnection)ASGIAppMessageReceiveScopeSend))Literalc @sReZdZdeejeefeeje ee de ddd d Z e eedd d d ZdS)SessionMiddlewaresessionu/laxF)rstrictnoneN)app secret_keysession_cookiemax_agepath same_site https_onlyreturncCsH||_tt||_||_||_||_d||_|rD|jd7_dS)Nzhttponly; samesite=z; secure) r itsdangerousZTimestampSignerstrsignerrrrsecurity_flags)selfrrrrrrrr$j/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/starlette/middleware/sessions.py__init__s  zSessionMiddleware.__init__)scopereceivesendrcsddvr$|IdHdSt}dj|jvr|jjd}z,jj|jd}t t |d<dWqt yid<Yq0nid<t ddfd d }||IdHdS) Ntype)httpZ websocketTutf-8)rrF)messagercs|ddkrdrttdd}j|}t|d}djj| dj j rjdj dnd j d }| d |n4st|d}d jjd j dj d}| d ||IdHdS)Nr*zhttp.response.startrr,)r'z?{session_cookie}={data}; path={path}; {max_age}{security_flags}zMax-Age=z; )rdatarrr"z Set-Cookiez?{session_cookie}={data}; path={path}; {expires}{security_flags}nullz'expires=Thu, 01 Jan 1970 00:00:00 GMT; )rr/rexpiresr")rjsondumpsencoder!signrformatrdecoderrr"append)r-r/headers header_valueZinitial_session_was_emptyr'r#r)r$r% send_wrapper:s0     z0SessionMiddleware.__call__..send_wrapper) rrrcookiesr4r!Zunsignrr2loadsrrr )r#r'r(r) connectionr/r<r$r;r%__call__'s    zSessionMiddleware.__call__)rrrrF)__name__ __module__ __qualname__rtypingUnionr rOptionalintrboolr&r r r r@r$r$r$r%rs   r)r2sysrDbase64rrrZitsdangerous.excrZstarlette.datastructuresrrZstarlette.requestsrZstarlette.typesrr r r r version_inforZtyping_extensionsrr$r$r$r%s