
    f j                    `    d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
mZmZ  G d d          ZdS )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
    )annotations)Unioncast)ASGI3ApplicationASGIReceiveCallableASGISendCallable	HTTPScopeScopeWebSocketScopec                  *    e Zd Z	 dddZddZddZdS )ProxyHeadersMiddleware	127.0.0.1appr   trusted_hostslist[str] | strreturnNonec                    || _         t          |t                    r%d |                    d          D             | _        nt          |          | _        d| j        v | _        d S )Nc                6    h | ]}|                                 S  strip.0items     tC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\uvicorn/middleware/proxy_headers.py	<setcomp>z2ProxyHeadersMiddleware.__init__.<locals>.<setcomp>   s     !T!T!T4$**,,!T!T!T    ,*)r   
isinstancestrsplitr   setalways_trust)selfr   r   s      r   __init__zProxyHeadersMiddleware.__init__   sj    
 mS)) 	4!T!T=;N;Ns;S;S!T!T!TD!$]!3!3D4#55r   x_forwarded_for_hosts	list[str]
str | Nonec                b    | j         r|d         S t          |          D ]}|| j        vr|c S d S )Nr   )r%   reversedr   )r&   r(   hosts      r   get_trusted_client_hostz.ProxyHeadersMiddleware.get_trusted_client_host    sU     	,(++233 	 	D4--  tr   scoper
   receiver   sendr   c                  K   |d         dv rt          t          d         |          }|                    d          }|r|d         nd }| j        s	|| j        v rt          |d                   }d|v rX|d                             d                                          }|d         d	k    r|                    d
d          |d<   n||d<   d|v rX|d                             d          }d |	                    d          D             }	| 
                    |	          }
d}|
|f|d<   |                     |||           d {V S )Ntype)http	websocket)r	   r   clientr   headerss   x-forwarded-protolatin1r5   r4   wsschemes   x-forwarded-forc                6    g | ]}|                                 S r   r   r   s     r   
<listcomp>z3ProxyHeadersMiddleware.__call__.<locals>.<listcomp>A   s     ,a,a,adTZZ\\,a,a,ar   r   )r   r   getr%   r   dictdecoder   replacer#   r.   r   )r&   r/   r0   r1   client_addrclient_hostr7   x_forwarded_protox_forwarded_forr(   r-   ports               r   __call__zProxyHeadersMiddleware.__call__*   s     =11 	3<=uEEE27))H2E2EK,7A+a..TK  3K43E$E 3uY/00'72 < )00D(E(L(LX(V(V(\(\(^(^%V}3 <*;*C*CFD*Q*Qh*;h%0 3 '..@&A&H&H&R&RO,a,aoF[F[\_F`F`,a,a,a)778MNNDD'+TlE(OXXeWd333333333r   N)r   )r   r   r   r   r   r   )r(   r)   r   r*   )r/   r
   r0   r   r1   r   r   r   )__name__
__module____qualname__r'   r.   rF   r   r   r   r   r      sZ         *5
6 
6 
6 
6 
6   4 4 4 4 4 4r   r   N)__doc__
__future__r   typingr   r   uvicorn._typesr   r   r   r	   r
   r   r   r   r   r   <module>rN      s   	 	 # " " " " "         t t t t t t t t t t t t t t t t34 34 34 34 34 34 34 34 34 34r   