a c@sddlZddlZddlmZddlmZddlmZmZm Z ddl m Z m Z m Z mZmZejegejefZejeegejefZedZGdddZGd d d e ZdS) N)BackgroundTask)Request) ContentStreamResponseStreamingResponse)ASGIAppMessageReceiveScopeSendTc@sLeZdZd eejeddddZee e ddddZ e e edd d ZdS) BaseHTTPMiddlewareN)appdispatchreturncCs||_|dur|jn||_dSN)rr dispatch_func)selfrrrf/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/starlette/middleware/base.py__init__szBaseHTTPMiddleware.__init__)scopereceivesendrc sddkr$||IdHdStttdfdd }t4IdHNt|d}||IdH}|||IdHWdIdHq1IdHs0YdS)Ntypehttp)requestrcs6dt\tdfdd ddfdd }tddfdd ddfd d } | |z@IdH}|d d}|d d kr|durIdH}Wn(tjydur؈tdYn0|d dksJtj t dfdfdd }t |d||d}|d|_ |S)N)rc srddiSt4IdHXtjgtjtftdfdd }|j|j IdH}WdIdHq1IdHs0YrddiS|S)Nrzhttp.disconnect)funcrcs|IdH}j|Sr)Z cancel_scopecancel)rresult task_grouprrwrap)s  z[BaseHTTPMiddleware.__call__..call_next..receive_or_disconnect..wrap) is_setanyiocreate_task_grouptypingCallable Awaitabler start_soonwaitr)r"message)r response_sentr rreceive_or_disconnect#s$:zMBaseHTTPMiddleware.__call__..call_next..receive_or_disconnectcsIdHdSr)r*closer) recv_streamr,rr"close_recv_stream_on_response_sent6szZBaseHTTPMiddleware.__call__..call_next..close_recv_stream_on_response_sent)r+rcs0z|IdHWntjy*YdS0dSr)rr$ZBrokenResourceError)r+) send_streamrr send_no_error:szEBaseHTTPMiddleware.__call__..call_next..send_no_errorc s~4IdHXzIdHWn(tyN}z|WYd}~n d}~00WdIdHqz1IdHsp0YdSr)r Exception)exc)app_excr-rrr2r1rrcoroAs z.call_next..coroinforhttp.response.debugzNo response returned.zhttp.response.startc s4IdHP2z23dHW}|ddks.J|dd}|r|Vq6WdIdHqr1IdHsh0Ydur~dS)Nrzhttp.response.bodybody)get)r+r9)r5r/rr body_streamYs 4zCBaseHTTPMiddleware.__call__..call_next..body_streamstatus) status_codecontentr7headers) r$Zcreate_memory_object_streamrr)rr;Z EndOfStream RuntimeErrorr&AsyncGeneratorbytes_StreamingResponseZ raw_headers)rr0r6r+r7r<responser,rrr!)r5r-r/rr2r1r call_nexts0       z.BaseHTTPMiddleware.__call__..call_next)r)rr$Eventrrr%rset)rrrrrGrrErrFr__call__s K zBaseHTTPMiddleware.__call__)rrGrcs tdSr)NotImplementedError)rrrGrrrrpszBaseHTTPMiddleware.dispatch)N)__name__ __module__ __qualname__rr&OptionalDispatchFunctionrr r r rJrRequestResponseEndpointrrrrrrr s  Yr c sreZdZd eeejejeefejeeje ejejeej fddfdd Z e ddfdd Z ZS) rDN)r?r>r@ media_type backgroundr7rcs||_t|||||dSr)_infosuperr)rr?r>r@rSrTr7 __class__rrrws z_StreamingResponse.__init__)rrcs.|jr|d|jdIdHt|IdHS)Nr8)rr7)rUrVstream_response)rrrWrrrYsz"_StreamingResponse.stream_response)rRNNNN)rLrMrNrintr&rOMappingstrrAnyrr rY __classcell__rrrWrrDvs rD)r&r$Zstarlette.backgroundrZstarlette.requestsrZstarlette.responsesrrrZstarlette.typesrrr r r r'r(rQrPTypeVarr r rDrrrrs   e