
    9j                    X    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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
    )annotations)Unioncast)ASGI3ApplicationASGIReceiveCallableASGISendCallable	HTTPScopeScopeWebSocketScopec                  2    e Zd Z	 d	 	 	 	 	 ddZddZddZy)	ProxyHeadersMiddlewarec                    || _         t        |t              r3|j                  d      D ch c]  }|j	                          c}| _        nt        |      | _        d| j
                  v | _        y c c}w )N,*)app
isinstancestrsplitstriptrusted_hostssetalways_trust)selfr   r   items       `/media/conek/DATA/Code/OCR/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/c                j    | j                   r|d   S t        |      D ]  }|| j                  vs|c S  y )Nr   )r   reversedr   )r   x_forwarded_for_hostshosts      r   get_trusted_client_hostz.ProxyHeadersMiddleware.get_trusted_client_host    sC    (++23 	D4---	     c                T  K   |d   dv rt        t        d   |      }|j                  d      }|r|d   nd }| j                  s|| j                  v rt        |d         }d|v rE|d   j                  d      j                         }|d   d	k(  r|j                  d
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&   r%   wsschemes   x-forwarded-forr   )r   r   getr   r   dictdecoder   replacer   r!   r   )r   scopereceivesendclient_addrclient_hostr(   x_forwarded_protox_forwarded_forr   r   r    ports                r   __call__zProxyHeadersMiddleware.__call__*   sD    =11<=uEE27))H2EK,7+a.TK  K43E3E$EuY/0'72 )00D(E(L(LX(V(\(\(^%V}3*;*C*CFD*Qh*;h%0 '..@&A&H&H&ROFUF[F[\_F`,adTZZ\,a),a778MNDD'+TlE(OXXeWd333 -b
 4s   CD(D!*2D(D&
D(N)z	127.0.0.1)r   r   r   zlist[str] | strreturnNone)r   z	list[str]r9   z
str | None)r0   r
   r1   r   r2   r   r9   r:   )__name__
__module____qualname__r   r!   r8    r"   r   r   r      s2     *5
6
6 '
6 
	
64r"   r   N)__doc__
__future__r   typingr   r   uvicorn._typesr   r   r   r	   r
   r   r   r>   r"   r   <module>rC      s"   	 #  t t34 34r"   