
    &`iw                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZmZmZmZmZmZ d dlZd dlZd dlmZ d dlmZ d dlmZ d d	lmZ d d
l m!Z! d dl"m#Z#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;m<Z< d dl=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZDmEZEmFZF  ejG        e:          ZH ed           G d d                      ZIdeJde%fdZK	 dDdee         d eLdee$         fd!ZM G d" d#          ZNd$ ZO G d% d&e'          ZP G d' d(          ZQd)eddfd*ZRd+ej        deSfd,ZT G d- d.          ZUd/ede!gfd0ZV G d1 d2          ZWd3e#d/ee         de#fd4ZXd5d6d3e#d7eBd8e jY        d9eSde jZ        f
d:Z[d;e\d<e]d=e^de<fd>Z_d?e<d@eSdee$         fdAZ`d7eBdeBfdBZad7eBdeBfdCZbdS )E    N)deque)deepcopy)	dataclass)	AnyAsyncGenerator	AwaitableCallableListOptionalTupleTypeUnion)FastAPI)jsonable_encoder)version)MutableHeaders)
Middleware)ASGIAppMessageReceiveScopeSend)Config)
LifespanOn)is_ipv6)IS_PYDANTIC_2)RayActorErrorRayTaskError)RequestMetadata)#RAY_SERVE_HTTP_KEEP_ALIVE_TIMEOUT_S)RAY_SERVE_HTTP_PROXY_CALLBACK_IMPORT_PATH&RAY_SERVE_REQUEST_PROCESSING_TIMEOUT_SSERVE_HTTP_REQUEST_ID_HEADERSERVE_LOGGER_NAME)ResponseStatus)call_function_from_import_pathgenerate_request_idserve_encoders)HTTPOptions)BackPressureErrorDeploymentUnavailableErrorRayServeExceptionT)frozenc                   l    e Zd ZU eed<   eed<   eed<   deeeef         fdZde	j
        j        fdZdS )ASGIArgsscopereceivesendreturnc                 *    | j         | j        | j        fS N)r0   r1   r2   selfs    p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/_private/http_util.pyto_args_tuplezASGIArgs.to_args_tupleB   s    
DL$)44    c                 L    t          j        j        |                                  S r5   )	starletterequestsRequestr9   r6   s    r8   to_starlette_requestzASGIArgs.to_starlette_requestE   s$    !)!!
 	
r:   N)__name__
__module____qualname__r   __annotations__r   r   r   r9   r<   r=   r>   r?    r:   r8   r/   r/   <   s|         LLL
JJJ5uUGT%9: 5 5 5 5
i&8&@ 
 
 
 
 
 
r:   r/   serialized_bodyr3   c                      d fd}|S )zAReturns an ASGI receiver that returns the provided buffered body.Fc                  v   K   r-t          j                    } |                                  d {V  ddddS )NThttp.requestF)bodytype	more_body)asyncioEventwait)block_foreverreceivedrE   s    r8   mock_receivez0make_buffered_asgi_receive.<locals>.mock_receiveR   sU        	'#MOOM$$&&&&&&&&&'eTTTr:   rD   )rE   rQ   rP   s   ` @r8   make_buffered_asgi_receiverR   K   s7    
 HU U U U U U r:      objstatus_codec                 >   d}d}| d}d}nt          | t                    r| }d}nkt          | t                    r|                     d          }d}n>t	          j        t          | t                    d                                          }d	}d
|d|ggdd|dgS )zSerializes the provided object and converts it to ASGI messages.

    These ASGI messages can be sent via an ASGI `send` interface to comprise an HTTP
    response.
    Nr:   s
   text/plainzutf-8s   text/plain; charset=utf-8)custom_encoder),:)
separatorss   application/jsonhttp.response.starts   content-type)rJ   statusheaderszhttp.response.body)rJ   rI   )
isinstancebytesstrencodejsondumpsr   r(   )rT   rU   rI   content_types       r8   convert_object_to_asgi_messagesre   b   s     DL
{$	C		 +$	C		 +zz'""3
 zS@@@!
 
 
 &(( 	 + *!(,78	
 	

 &t44 r:   c                        e Zd ZdZddZd ZdS )ResponseaQ  ASGI compliant response class.

    It is expected to be called in async context and pass along
    `scope, receive, send` as in ASGI spec.

    >>> from ray.serve.http_util import Response  # doctest: +SKIP
    >>> scope, receive = ... # doctest: +SKIP
    >>> await Response({"k": "v"}).send(scope, receive, send) # doctest: +SKIP
    NrS   c                 2    t          ||          | _        dS )zConstruct a HTTP Response based on input type.

        Args:
            content: Any JSON serializable object.
            status_code (int, optional): Default status code is 200.
        )rT   rU   N)re   	_messages)r7   contentrU   s      r8   __init__zResponse.__init__   s$     9#
 
 
r:   c                 @   K   | j         D ]} ||           d {V  d S r5   )ri   )r7   r0   r1   r2   messages        r8   r2   zResponse.send   sD      ~ 	  	 G$w--	  	 r:   NrS   )r@   rA   rB   __doc__rk   r2   rD   r:   r8   rg   rg      sA         

 

 

 

         r:   rg   c                    K   g }d}|rC |             d {V }|d         dk    sJ |d         }|                     |d                    |Cd                    |          S )NTrJ   rH   rK   rI   r:   )appendjoin)r0   r1   r2   body_bufferrK   rm   s         r8   receive_http_bodyrt      s      KI
 ,		//////v.0000K(	76?+++  , 88K   r:   c                       e Zd ZdZd Zd ZdefdZdefdZ	defdZ
d	 Zd
ee         fdZd
efdZdej        d
eee         df         fdZdS )MessageQueueaq  Queue enables polling for received or sent messages.

    Implements the ASGI `Send` interface.

    This class:
        - Is *NOT* thread safe and should only be accessed from a single asyncio
          event loop.
        - Assumes a single consumer of the queue (concurrent calls to
          `get_messages_nowait` and `wait_for_message` is undefined behavior).
    c                 x    t                      | _        t          j                    | _        d| _        d | _        d S )NF)r   _message_queuerL   rM   _new_message_event_closed_errorr6   s    r8   rk   zMessageQueue.__init__   s.    #gg")-//r:   c                 F    d| _         | j                                         dS )zClose the queue, rejecting new messages.

        Once the queue is closed, existing messages will be returned from
        `get_messages_nowait` and subsequent calls to `wait_for_message` will
        always return immediately.
        TN)rz   ry   setr6   s    r8   closezMessageQueue.close   s&     ##%%%%%r:   ec                     || _         d S r5   )r{   )r7   r   s     r8   	set_errorzMessageQueue.set_error   s    r:   rm   c                 l    | j                             |           | j                                         d S r5   )rx   rq   ry   r}   r7   rm   s     r8   
put_nowaitzMessageQueue.put_nowait   s4    ""7+++##%%%%%r:   c                 `   K   | j         rt          d          |                     |           dS )zSend a message, putting it on the queue.

        `RuntimeError` is raised if the queue has been closed using `.close()`.
        z6New messages cannot be sent after the queue is closed.N)rz   RuntimeErrorr   r   s     r8   __call__zMessageQueue.__call__   s:      
 < 	YWXXX     r:   c                 Z   K   | j         s!| j                                         d{V  dS dS )a   Wait until at least one new message is available.

        If a message is available, this method will return immediately on each call
        until `get_messages_nowait` is called.

        After the queue is closed using `.close()`, this will always return
        immediately.
        N)rz   ry   rN   r6   s    r8   wait_for_messagezMessageQueue.wait_for_message   sI       | 	1)..00000000000	1 	1r:   r3   c                     g }t          | j                  dk    rD|                    | j                                                   t          | j                  dk    D| j                                         |S )a  Returns all messages that are currently available (non-blocking).

        At least one message will be present if `wait_for_message` had previously
        returned and a subsequent call to `wait_for_message` blocks until at
        least one new message is available.
        r   )lenrx   rq   popleftry   clear)r7   messagess     r8   get_messages_nowaitz MessageQueue.get_messages_nowait   st     $%&&**OOD/7799::: $%&&** 	%%'''r:   c                   K   | j         r| j         | j                                         d{V  t          | j                  dk    rS| j                                        }t          | j                  dk    r | j        s| j                                         |S t          | j                  dk    r| j         r| j         t          | j                  dk    r| j        r	t          dS dS )a  This blocks until a message is ready.

        This method should not be used together with get_messages_nowait.
        Please use either `get_one_message` or `get_messages_nowait`.

        Raises:
            StopAsyncIteration: if the queue is closed and there are no
                more messages.
            Exception (self._error): if there are no more messages in
                the queue and an error has been set.
        Nr   )	r{   ry   rN   r   rx   r   rz   r   StopAsyncIteration)r7   msgs     r8   get_one_messagezMessageQueue.get_one_message   s       ; 	+%**,,,,,,,,,t"##a''%--//C4&''1,,T\,'--///J$%%**t{*+$%%**t|*$$ +***r:   call_futNc                  K   d}	 	 t          j        |                                           }t          j        ||gt           j                   d{V \  }}|                                 }|r|W V  ||v rnr|                                }||d	 |                                s|                                 |*|                                s|                                 dS dS dS # |                                s|                                 |)|                                s|                                 w w w xY w)a  Repeatedly consume messages from the queue and yield them.

        This is used to fetch queue messages in the system event loop in
        a thread-safe manner.

        Args:
            call_fut: The async Future pointing to the task from the user
                code event loop that is pushing messages onto the queue.

        Yields:
            List[Any]: Messages from the queue.
        NT)return_when)	rL   create_taskr   rN   FIRST_COMPLETEDr   	exceptiondonecancel)r7   r   wait_for_msg_taskr   _r   r   s          r8   fetch_messages_from_queuez&MessageQueue.fetch_messages_from_queue  s       !	+$+$78M8M8O8O$P$P! '01w?V! ! !      a  3355 #"NNNN t## ""$$A}T!  ==?? "!!! ,5F5K5K5M5M,!((***** -,,, ==?? "!!! ,5F5K5K5M5M,!((**** -,s   BC+ +AE)r@   rA   rB   ro   rk   r~   BaseExceptionr   r   r   r   r   r
   r   r   rL   Futurer   r   r   rD   r:   r8   rv   rv      s	       	 	  & & &=    &' & & & &!g ! ! ! !
1 
1 
1T']    %w % % % %<)+)+	S	4	()+ )+ )+ )+ )+ )+r:   rv   c            	           e Zd ZdZdededeegee         f         fdZ	de
fdZedej        fd            Zd	 Zde
fd
ZdS )ASGIReceiveProxyzProxies ASGI receive from an actor.

    The `receive_asgi_messages` callback will be called repeatedly to fetch messages
    until a disconnect message is received.
    r0   request_metadatareceive_asgi_messagesc                 X    |d         | _         d | _        || _        || _        d | _        d S )NrJ   )_type_queue_request_metadata_receive_asgi_messages_disconnect_message)r7   r0   r   r   s       r8   rk   zASGIReceiveProxy.__init__J  s4     6]
!1&;##'   r:   r3   c                 *    | j         dk    rdddS ddiS )a7  Return the appropriate disconnect message based on the connection type.

        HTTP ASGI spec:
            https://asgi.readthedocs.io/en/latest/specs/www.html#disconnect-receive-event

        WS ASGI spec:
            https://asgi.readthedocs.io/en/latest/specs/www.html#disconnect-receive-event-ws
        	websocketwebsocket.disconnecti  )rJ   coderJ   http.disconnect)r   r6   s    r8   _get_default_disconnect_messagez0ASGIReceiveProxy._get_default_disconnect_messageW  s4     :$$.   -..r:   c                 N    | j         t          j                    | _         | j         S r5   )r   rL   Queuer6   s    r8   queuezASGIReceiveProxy.queuei  s    ;!-//DK{r:   c                   K   	 	 |                      | j                   d{V }t          j        |          D ]0}| j                            |           |d         dv r
|| _         dS 1ns# t          $ r9 |                                 }| j                            |           || _        Y dS t          $ r%}| j                            |           Y d}~dS d}~ww xY w)a  Fetch messages repeatedly until a disconnect message is received.

        If a disconnect message is received, this function exits and returns it.

        If an exception occurs, it will be raised on the next __call__ and no more
        messages will be received.
        TNrJ   >   r   r   )
r   r   pickleloadsr   r   r   KeyErrorr   	Exception)r7   pickled_messagesrm   r   s       r8   fetch_until_disconnectz'ASGIReceiveProxy.fetch_until_disconnectp  s9     	)-)D)D** * $ $ $ $ $ $   &|,<==  GJ))'222v*UUU3:0 V     >>@@
%%g...+2(   
%%a((('	s$   A"A+ )A+ +?C-	C6CCc                    K   | j                                         r| j        | j        S | j                                          d{V }t	          |t
                    r||S )zReturn the next message once available.

        This will repeatedly return a disconnect message once it's been received.
        N)r   emptyr   getr^   r   r   s     r8   r   zASGIReceiveProxy.__call__  sn      
 : 	,$":"F++
((((((((gy)) 	Mr:   N)r@   rA   rB   ro   r   r   r	   r   r_   rk   r   r   propertyrL   r   r   r   r   rD   r:   r8   r   r   C  s         (( *(  ((99U;K(KL	( ( ( (/ / / / /$ w}    X  @      r:   r   clsc                    ddl m}m} ddlmm d }fd| j        D             } |            }|D ]}| j                            |           |j        }t          j
        |          }	t          |	j                                                  }
t          |
          dk    rt          d          |
d         }|                     ||                    }|gd |
d	d
         D             z   }|	                    |          }||j        _        |j        _        |j                            |           	|                     |           t                      | j        D ]|}t+          |f          st,          s-t+          |          r|j        r|j        j        |j        _        t7          |j        dd
          }||k    r                    |           }fd| j        D             | j        d
d
<   d
S )a_  Transform the `cls`'s methods and class annotations to FastAPI routes.

    Modified from
    https://github.com/dmontagu/fastapi-utils/blob/master/fastapi_utils/cbv.py

    Usage:
    >>> from fastapi import FastAPI
    >>> app = FastAPI() # doctest: +SKIP
    >>> class A: # doctest: +SKIP
    ...     @app.route("/{i}") # doctest: +SKIP
    ...     def func(self, i: int) -> str: # doctest: +SKIP
    ...         return self.dep + i # doctest: +SKIP
    >>> # just running the app won't work, here.
    >>> make_fastapi_class_based_view(app, A) # doctest: +SKIP
    >>> # now app can be run properly
    r   )	APIRouterDepends)APIRouteAPIWebSocketRoutec                  D   K   ddl m}  |                                 j        S )Nr   serve)rayr   get_replica_contextservable_objectr   s    r8   get_current_servable_instancezDmake_fastapi_class_based_view.<locals>.get_current_servable_instance  s-      ((**::r:   c                 z    g | ]6t          f          t          fd j        D                       47S )c              3   x   K   | ]4}|t           uj        j                            |j        d z             V  5dS ).N)objectendpointrB   
startswith).0baseroutes     r8   	<genexpr>z;make_fastapi_class_based_view.<locals>.<listcomp>.<genexpr>  sU       
 
6!! N'2243Ds3JKK!!!!
 
r:   )r^   any__mro__)r   r   r   r   r   s    @r8   
<listcomp>z1make_fastapi_class_based_view.<locals>.<listcomp>  s~        	58%6788  
 
 
 

 
 
 
 
  r:   zOMethods in FastAPI class-based view must have ``self`` as their first argument.)defaultc                 X    g | ]'}|                     t          j        j                   (S ))kind)replaceinspect	ParameterKEYWORD_ONLY)r   	parameters     r8   r   z1make_fastapi_class_based_view.<locals>.<listcomp>  sA     1
 1
 1
  7#4#ABB1
 1
 1
r:      N)
parameters
_serve_clsc                     g | ]}|v|	S rD   rD   )r   rroutes_to_removes     r8   r   z1make_fastapi_class_based_view.<locals>.<listcomp>  s$    XXX1aGW>W>WQ>W>W>Wr:   )fastapir   r   fastapi.routingr   r   routesremover   r   	signaturelistr   valuesr   r,   r   __signature__r   rq   include_routerr^   r   response_modelresponse_fieldouter_type_secure_cloned_response_fieldgetattr)fastapi_appr   r   r   r   class_method_routes
new_routerr   old_endpointold_signatureold_parametersold_self_parameternew_self_parameternew_parametersnew_signature	serve_clsr   r   r   s    `              @@@r8   make_fastapi_class_based_viewr     s   $ +*******;;;;;;;;; ; ;      '  4 J$ ( (!!%((( ~),77m6==??@@~!###(   ,A./77G9:: 8 
 
 -- 1
 1
 ,ABB/	1
 1
 1
 
 &---HH'4$$'!  ''''z***vv# + +%(,=!>?? 	 		 5(++			
 $		 $0 .:
 ENL$??	 Y#%5%5##E***XXXX(:XXXKqqqr:   sockc                    	 |                      t          j        t          j        d           t	          t          d          r,|                      t          j        t          j        d           n!|                      t          j        dd           dS # t          $ r)}t                              d| d           Y d}~dS d}~ww xY w)	zMutate a socket object to allow multiple process listening on the same port.

    Returns:
        success: whether the setting was successful.
    r   SO_REUSEPORT   Tz'Setting SO_REUSEPORT failed because of z. SO_REUSEPORT is disabled.NF)	
setsockoptsocket
SOL_SOCKETSO_REUSEADDRhasattrr  r   loggerdebug)r  r   s     r8   set_socket_reuse_portr    s     	)6+>BBB6>** 		6OOF-v/BAFFFF OOF-r1555t   TaTTT	
 	
 	
 uuuuu	s   BB 
CB??Cc            	           e Zd ZdZdeeef         fdZedefd            Z	ede
e         fd            Zd Zded	ed
ede
e         fdZd ZdS )ASGIAppReplicaWrapperz;Provides a common wrapper for replicas running an ASGI app.app_or_funcc           	          t          j        |          r |            | _        n|| _        t          t	          | j        dd d d                    | _        t          | j        _        d S )NonF)lifespan	log_level
log_config
access_log)r   
isfunction	_asgi_appr   r   _serve_asgi_lifespanr
  )r7   r  s     r8   rk   zASGIAppReplicaWrapper.__init__.  su    k** 	)([]]DNN(DN %/   %
 %
! ,2!(((r:   r3   c                     | j         S r5   r  r6   s    r8   appzASGIAppReplicaWrapper.appE  s
    ~r:   c                 R    t          | j        t                    r| j        j        S d S r5   )r^   r  r   docs_urlr6   s    r8   	docs_pathzASGIAppReplicaWrapper.docs_pathI  s+    dng.. 	+>**	+ 	+r:   c                    K   ddl m}  || j        j        t          j                  5  | j                                         d {V  | j        j        rt          d          	 d d d            d S # 1 swxY w Y   d S )Nr   LoggingContextlevelz=ASGI lifespan startup failed. Check replica logs for details.)	 ray.serve._private.logging_utilsr!  r  r
  loggingWARNINGstartupshould_exitr   r7   r!  s     r8   _run_asgi_lifespan_startupz0ASGIAppReplicaWrapper._run_asgi_lifespan_startupN  s       	DCCCCC^D5<GOTTT 	 	+33555555555(4 "S  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   ;A33A7:A7r0   r1   r2   c                 D   K   |                      |||           d{V  dS )z Calls into the wrapped ASGI app.Nr  )r7   r0   r1   r2   s       r8   r   zASGIAppReplicaWrapper.__call__Z  sO       nn
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r:   c                    K   ddl m}  || j        j        t          j                  5  | j                                         d {V  d d d            d S # 1 swxY w Y   d S )Nr   r   r"  )r$  r!  r  r
  r%  r&  shutdownr)  s     r8   __del__zASGIAppReplicaWrapper.__del__i  s       	DCCCCC^D5<GOTTT 	7 	7+44666666666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s    AAAN)r@   rA   rB   ro   r   r   r	   rk   r   r  r   r`   r  r*  r   r   r   r   r.  rD   r:   r8   r  r  +  s        EE2E'8*;$< 2 2 2 2. W    X +8C= + + + X+
 
 


 
 	

 
'	
 
 
 
7 7 7 7 7r:   r  middlewaresc                     | g } t          | t                    st          d          | D ]D}t          t	          |          t
                    s t          dt	          |           d          E| S )a4  Validate the return value of HTTP proxy callback.

    Middlewares should be a list of Starlette middlewares. If it is None, we
    will treat it as an empty list. If it is not a list, we will raise an
    error. If it is a list, we will check if all the items in the list are
    Starlette middlewares.
    Nz@HTTP proxy callback must return a list of Starlette middlewares.zMHTTP proxy callback must return a list of Starlette middlewares, instead got z type item in the list.)r^   r   
ValueError
issubclassrJ   r   )r/  
middlewares     r8   #validate_http_proxy_callback_returnr4  r  s     k4(( N
 
 	
 & 	 	Jd:..
;;  M#'
#3#3M M M  
 r:   c                   .    e Zd ZdefdZdededefdZdS )RequestIdMiddlewarer  c                     || _         d S r5   )_app)r7   r  s     r8   rk   zRequestIdMiddleware.__init__  s    			r:   r0   r1   r2   c                   K   t          |          }|                    t                    )t                      |                    t                     dt
          ffd}|                     |||           d {V  d S )Nr0   rm   c                    K   | d         dk    r&t          |           }|                    d           | d         dk    r| d<    |            d {V  d S )NrJ   r[   r:  zX-Request-IDzwebsocket.accept)r   rq   )rm   r]   
request_idr2   s     r8   send_with_request_idz:RequestIdMiddleware.__call__.<locals>.send_with_request_id  s{      v"777(w777~z:::v"444*4'$w--r:   )r   r   r#   r'   rq   r   r8  )r7   r0   r1   r2   r]   r=  r<  s      `  @r8   r   zRequestIdMiddleware.__call__  s       u---[[!=>>
,..JNN7DDD	  	  	  	  	  	  	  	  iiw(<===========r:   N)	r@   rA   rB   r   rk   r   r   r   r   rD   r:   r8   r6  r6    sX        G    >E >G >4 > > > > > >r:   r6  r  c                    t          t                    g|z   D ]e}t          j        t          j                  t          j        d          k     r |j        | fi |j        } J |j        | g|j        R i |j	        } f| S )zyWrap the ASGI app with the provided middlewares.

    The built-in RequestIdMiddleware will always be applied first.
    z0.35.0)
r   r6  r   parser<   __version__r   optionsargskwargs)r  r/  r3  s      r8   _apply_middlewaresrD    s    
 ""5667+E 
 

=.//'-2I2III *.;;
(:;;CC !*.   # CC Jr:   F)enable_so_reuseporthttp_options
event_looprE  c                   K   t           |j                   t          j        t          |j                  rt          j        nt          j        t          j                  }|rt          |           	 |	                    |j        |j
        f           n3# t          $ r&}t          d|j         d|j
         d          |d}~ww xY wt          j        t          j        d          _        i }|j        rj|j        rc|j        |j        d}|j        r
|j        |d<   |j        r
|j        |d<   t*                              d	|j         d|j
         d
|j                    t/          j        t/          j         fdfd|j        |j
        |j        |j        |ddddd
|          }d |_        |                    |                    |g                    S )z{Start an HTTP server to run the ASGI app.

    Returns a task that blocks until the server exits (e.g., due to error).
    zFailed to bind to address 'rY   '.Nzuvicorn.error)ssl_keyfilessl_certfilessl_keyfile_passwordssl_ca_certszStarting HTTPS server on z with SSL certificate: c                       S r5   rD   )r  s   r8   <lambda>z(start_asgi_http_server.<locals>.<lambda>  s    C r:   ToffF)
factoryhostport	root_pathtimeout_keep_aliveloopr  r  r  r  )configc                      d S r5   rD   rD   r:   r8   rO  z(start_asgi_http_server.<locals>.<lambda>  s    T r:   )sockets)rD  r/  r  r   rR  AF_INET6AF_INETSOCK_STREAMr  bindrS  OSErrorr   r%  CRITICAL	getLoggerr#  rJ  rK  rL  rM  r
  infouvicornServerr   rT  keep_alive_timeout_sinstall_signal_handlersr   r   )r  rF  rG  rE  r  r   
ssl_kwargsservers   `       r8   start_asgi_http_serverrh    sI      S,":
;
;C="<#455I6> D  $d###		<$l&789999   S,*;SSl>OSSS
 
	 07/?Go&&, J 
L$= 
'3(5
 

 , 	S1=1RJ-.$ 	C)5)BJ~&A(9 A AL<M A A%1%>A A	
 	
 	
 ^~KKK
""",+@
 
 
 
  F( &2\F"!!&,,v,">">???s   4!B 
C !CCexcrequest_timeout_sr<  c           	         t          | t                    rt          ddd| d| d          S t          | t          j                  r2d| d}t
                              |           t          d	d|          S t          | t          t          f          rMt          | t                    r!t
          
                    d
|  ddi           t          dd| j                  S t          | t          t          f          r"t
          
                    d
|  ddi           nt
                              d           t          ddt          |                     S )N  TzRequest z timed out after zs.)r   is_errorrm   zClient for request z" disconnected, cancelling request.i  zRequest failed: log_to_stderrF)extra  z'Request failed due to unexpected error.i  )r^   TimeoutErrorr%   rL   CancelledErrorr
  ra  r*   r+   r   warningrm   r   r   r`   )ri  rj  r<  rm   s       r8   get_http_response_statusrt    s    #|$$  
QzQQ<MQQQ
 
 
 	
 
C/	0	0 
V
VVVG
 
 
 	

 
C+-GH	I	I 
c<(( 	UNN3c33OU;SNTTTK
 
 
 	
 cM<899 	HNN3c33OU;SNTTTTFGGGHH
 
 
 	
r:   r\   response_startedc                 R    |s	| j         dvrg S t          | j        | j                   S )N)rl  rp  )rU   )r   re   rm   )r\   ru  s     r8   send_http_response_on_exceptionrw  -  s>      6;j88	*K   r:   c                     t          |           } t          pddk    rt          | _        | j        st          r| j        pt          | _        | j        pg | _        | S )z7Enhanced configuration with component-specific options.r   )r   r    rd  rj  r"   r/  rF  s    r8   $configure_http_options_with_defaultsrz  8  sl     L))L 	,0qA55,O) % 
)O 
*T.T 	&  ,7=2Lr:   c                     t          |           } t          r\t                              dt           d           | j                            t          t          t                                         | S )Nz1Calling user-provided callback from import path 'rI  )r   r!   r
  ra  r/  extendr4  r&   ry  s    r8   configure_http_middlewaresr}  L  s    L))L 1 
>9> > >	
 	
 	
 	 ''/.=  	
 	
 	
 r:   rn   )crL   r   rb   r%  r   r  collectionsr   copyr   dataclassesr   typingr   r   r   r	   r
   r   r   r   r   r<   rb  r   r   fastapi.encodersr   	packagingr   starlette.datastructuresr   starlette.middlewarer   starlette.typesr   r   r   r   r   uvicorn.configr   uvicorn.lifespan.onr   ray._common.network_utilsr   ray._common.pydantic_compatr   ray.exceptionsr   r   ray.serve._private.commonr   ray.serve._private.constantsr    r!   r"   r#   r$   )ray.serve._private.proxy_request_responser%   ray.serve._private.utilsr&   r'   r(   ray.serve.configr)   ray.serve.exceptionsr*   r+   r,   r`  r
  r/   r_   rR   intre   rg   rt   rv   r   r   boolr  r  r4  r6  rD  AbstractEventLoopTaskrh  r   floatr`   rt  rw  rz  r}  rD   r:   r8   <module>r     s1                     ! ! ! ! ! !
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
            - - - - - -       3 3 3 3 3 3 + + + + + + B B B B B B B B B B B B B B ! ! ! ! ! ! * * * * * * - - - - - - 5 5 5 5 5 5 6 6 6 6 6 6 6 6 5 5 5 5 5 5              E D D D D D         
 ) ( ( ( ( (          
	,	-	- $
 
 
 
 
 
 
 
 '    0 36$ $	#$,/$	']$ $ $ $N               8
! 
! 
!N+ N+ N+ N+ N+4 N+ N+ N+bY Y Y Y Y Y Y YxlYD lYT lY lY lY lY^ $    :D7 D7 D7 D7 D7 D7 D7 D7N\   :> > > > > > > >.G $x. W    2 !&J@ J@ J@	J@J@ )	J@
 J@ \J@ J@ J@ J@Z#
	#
+0#
>A#
#
 #
 #
 #
L.2	']   { {    ([ [      r:   