a c@svddlZddlZddlZddlmZmZddlmZmZm Z m Z m Z GdddZ GdddZ eejdd d ZdS) N)HeadersMutableHeaders)ASGIAppMessageReceiveScopeSendc@s6eZdZd eeeddddZeeedddd Z dS) GZipMiddleware Napp minimum_size compresslevelreturncCs||_||_||_dSN)r rrselfr rrrf/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/starlette/middleware/gzip.py__init__ szGZipMiddleware.__init__scopereceivesendrcsh|ddkrPt|d}d|ddvrPt|j|j|jd}||||IdHdS||||IdHdS)Ntypehttp)rgzipAccept-Encoding)r)rget GZipResponderr rr)rrrrheadersZ responderrrr__call__s   zGZipMiddleware.__call__)r r ) __name__ __module__ __qualname__rintrrrrr#rrrrr s  r c@sFeZdZd eeeddddZeeeddddZ e dd d d Z dS) r!r Nr cCsF||_||_t|_i|_d|_d|_t|_ t j d|j |d|_ dS)NFwb)modefileobjr) r runattached_sendrinitial_messagestartedcontent_encoding_setioBytesIO gzip_bufferrGzipFile gzip_filerrrrrs zGZipResponder.__init__rcs ||_||||jIdHdSr)rr send_with_gzip)rrrrrrrr#*szGZipResponder.__call__messagercsP|d}|dkr4||_t|jdd}d|v|_n|dkrt|jrt|js`d|_||jIdH||IdHn|dkr|jsd|_|dd }|d d }t||jkr|s||jIdH||IdHn|s^|j ||j |j }t |jdd}d |d <tt||d<|d||d<||jIdH||IdHnzt |jdd}d |d <|d|d=|j ||j |d<|j d|j ||jIdH||IdHnr|dkrL|dd }|d d }|j ||s|j |j |d<|j d|j ||IdHdS)Nrzhttp.response.startr")rawzcontent-encodingzhttp.response.bodyTbody more_bodyFrzContent-EncodingzContent-Lengthrr)r,rr.r-rr lenrr3writecloser1getvaluerstrZadd_vary_headerseektruncate)rr6Z message_typer"r8r:rrrr4.s`                 zGZipResponder.send_with_gzip)r ) r$r%r&rr'rrrrr#rr4rrrrr!s r!r5cs tddS)Nzsend awaitable not set) RuntimeError)r6rrrr+psr+)rr/typingZstarlette.datastructuresrrZstarlette.typesrrrrrr r!NoReturnr+rrrrsS