
    df                     X    d Z ddlmZmZmZmZmZ ddlmZm	Z	m
Z
mZmZmZ  G d d      Zy)a  
This middleware can be used when a known proxy is fronting the application,
and is trusted to be properly setting the `X-Forwarded-Proto` and
`X-Forwarded-For` headers with the connecting client information.

Modifies the `client` and `scheme` information so that they reference
the connecting client, rather that the connecting proxy.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#Proxies
    )ListOptionalTupleUnioncast)ASGI3ApplicationASGIReceiveCallableASGISendCallable	HTTPScopeScopeWebSocketScopec                   h    e Zd Z	 d
dddeee   ef   ddfdZdee   dee   fdZ	 	 	 	 	 	 	 	 dd	Z	y)ProxyHeadersMiddlewareappr   trusted_hostsreturnNc                     || _         t        |t              r3|j                  d      D ch c]  }|j	                          c}| _        nt        |      | _        d| j
                  v | _        y c c}w )N,*)r   
isinstancestrsplitstripr   setalways_trust)selfr   r   items       Y/home/api-vastappli/venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py__init__zProxyHeadersMiddleware.__init__   s_    
 mS);H;N;Ns;S!T4$**,!TD!$]!3D4#5#55 "Us   A/x_forwarded_for_hostsc                 j    | j                   r|d   S t        |      D ]  }|| j                  vs|c S  y )Nr   )r   reversedr   )r   r    hosts      r   get_trusted_client_hostz.ProxyHeadersMiddleware.get_trusted_client_host$   sE     (++23 	D4---	     c                 B  K   |d   dv rt        t        d   |      }|j                  d      }|r|d   nd }| j                  s|| j                  v rt        |d         }d|v r<|d   j                  d      j                         }|d   d	k(  r|d
k(  rdnd|d<   n||d<   d|v rZ|d   j                  d      }|j                  d      D 	cg c]  }	|	j                          }
}	| j                  |
      }d}||f|d<   | j                  |||       d {   S c c}	w 7 	w)Ntype)http	websocket)r   r   clientr   headerss   x-forwarded-protolatin1r)   httpswsswsschemes   x-forwarded-forr   )r   r   getr   r   dictdecoder   r   r$   r   )r   scopereceivesendclient_addrclient_hostr+   x_forwarded_protox_forwarded_forr   r    r#   ports                r   __call__zProxyHeadersMiddleware.__call__0   sR     =11<=uEE5:YYx5HK,7+a.TK  K43E3E$EuY/0'72   45<<XFLLN & V}3%6'%AEt h +<h%0 '..@&A&H&H&RO1@1F1Fs1K-)-

-) -  778MNDD'+TlE(OXXeWd333- 4s   CD
D!2DD
D)z	127.0.0.1)r4   r   r5   r	   r6   r
   r   N)
__name__
__module____qualname__r   r   r   r   r   r$   r<    r%   r   r   r      sw     0;
6
6 T#Y^,
6 
	
6
%)#Y
	#
$4$4'<$4DV$4	$4r%   r   N)__doc__typingr   r   r   r   r   uvicorn._typesr   r	   r
   r   r   r   r   r@   r%   r   <module>rD      s&   	 6 5 =4 =4r%   