o
    S۷iI                     @   s   d dl Z d dlmZ d dlmZ d dlmZ er<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 dddZdddddddefddZdddZdddefddZd ddZdS )!    N)should_send_default_pii)_filter_headers)TYPE_CHECKING)Any)Dict)Optional)Union)Literal)AnnotatedValue
asgi_scoper   returnDict[str, str]c                 C   sT   i }| d D ]!\}}| d}| d}||v r#|| d | ||< q|||< q|S )z^
    Extract headers from the ASGI scope, in the format that the Sentry protocol expects.
    headerslatin-1z, )decode)r   r   raw_key	raw_valuekeyvalue r   Z/home/ubuntu/vllm_env/lib/python3.10/site-packages/sentry_sdk/integrations/_asgi_common.py_get_headers   s   


r   Dict[str, Any]default_schemezLiteral['ws', 'http']hostz$Optional[Union[AnnotatedValue, str]]c                 C   s   |  d|}|  dd}|  dd|  dd }|r!d|||f S |durF|\}}dd	dd	d
 |}||kr?d||||f S d|||f S |S )zR
    Extract URL from the ASGI scope, without also including the querystring.
    schemeserverN	root_path pathz	%s://%s%sP   i  )httphttpswswssz%s://%s:%s%s)get)r   r   r   r   r   r   portdefault_portr   r   r   _get_url"   s   r(   c                 C   s$   |  d}|s	dS tj|dS )zb
    Extract querystring from the ASGI scope, in the format that the Sentry protocol expects.
    query_stringNr   )r%   urllibparseunquoter   )r   qsr   r   r   
_get_query;   s   
r.   c              	   C   sd   t | }z|d dd  W S  ttfy   Y nw z|d W S  ty*   Y nw | dd S )zh
    Extract IP Address from the ASGI scope based on request headers with fallback to scope client.
    zx-forwarded-for,r   z	x-real-ipclient)r   splitstripKeyError
IndexErrorr%   )r   r   r   r   r   _get_ipE   s   
r5   c                 C   s   i }| d }|dv r2|  d|d< tt|  |d< }t| |d< t| |dkr)dnd| d|d	< |  d
}|rDt rDdt| i|d< |S )zG
    Returns data related to the HTTP request from the ASGI scope.
    type)r!   	websocketmethodr   r)   r!   r#   r   urlr0   REMOTE_ADDRenv)r%   r   r   r.   r(   r   r5   )r   request_datatyr   r0   r   r   r   _get_request_dataW   s   

r>   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r*   sentry_sdk.scoper   $sentry_sdk.integrations._wsgi_commonr   typingr   r   r   r   r   typing_extensionsr	   sentry_sdk.utilsr
   r   strr(   r.   r5   r>   r   r   r   r   <module>   s0    



