a c@sZddlZddlmZmZddlmZmZmZddlm Z m Z m Z m Z dZ GdddZdS)N)URLHeaders)PlainTextResponseRedirectResponseResponse)ASGIAppReceiveScopeSendz6Domain wildcard patterns must be like '*.example.com'.c@sBeZdZd eejejeeddddZ e e e ddddZ dS) TrustedHostMiddlewareNT)app allowed_hosts www_redirectreturncCsx|durdg}|D]@}d|ddvs.Jt|dr|dkr|dsJtq||_t||_d|v|_||_dS)N*z*.)ENFORCE_DOMAIN_WILDCARD startswithr listr allow_anyr)selfr r rpatternrm/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/starlette/middleware/trustedhost.py__init__ s  zTrustedHostMiddleware.__init__)scopereceivesendrc s|js|ddvr*||||IdHdSt|d}|dddd}d}d}|jD]B}||ks|d r||d drd }qqXd ||krXd }qX|r||||IdHnT|r|jrt |d} | j d | j d } t t | d} n tddd} | |||IdHdS)Ntype)httpZ websocket)rhost:rFrrTzwww.)netloc)urlzInvalid host headeri) status_code)rr rgetsplitr rendswithrrreplacer#rstrr) rrrrheadersr Z is_valid_hostZfound_www_redirectrr$Z redirect_urlresponserrr__call__s2      zTrustedHostMiddleware.__call__)NT)__name__ __module__ __qualname__rtypingOptionalSequencer*boolrr rr r-rrrrr s r )r1Zstarlette.datastructuresrrZstarlette.responsesrrrZstarlette.typesrrr r rr rrrrs