• File: proxy.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/paste/__pycache__/proxy.cpython-37.pyc
  • Date Modified: 12/01/2019 7:09 PM
  • File size: 7.1 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

aN'@sxdZddlZddlZddlZddlmZddlmZdZGddde	Z
dd	d
ZGddde	Zd
dZ
dddZdS)a
An application that proxies WSGI requests to a remote server.

TODO:

* Send ``Via`` header?  It's not clear to me this is a Via in the
  style of a typical proxy.

* Other headers or metadata?  I put in X-Forwarded-For, but that's it.

* Signed data of non-HTTP keys?  This would be for things like
  REMOTE_USER.

* Something to indicate what the original URL was?  The original host,
  scheme, and base path.

* Rewriting ``Location`` headers?  mod_proxy does this.

* Rewriting body?  (Probably not on this one -- that can be done with
  a different middleware that wraps this middleware)

* Example::  
    
    use = egg:Paste#proxy
    address = http://server3:8680/exist/rest/db/orgs/sch/config/
    allowed_request_methods = GET
  
N)httpexceptions)aslist)ztransfer-encodingZ
connectionz
keep-alivezproxy-authenticatezproxy-authorizationteZtrailersupgradec@seZdZdddZddZdS)ProxycCs^||_t||_|jd|_|jd|_|jd|_dd|D|_dd|D|_	dS)NrcSsg|]}|r|qSr)lower).0xrr</opt/alt/python37/lib/python3.7/site-packages/paste/proxy.py
<listcomp>>sz"Proxy.__init__.<locals>.<listcomp>cSsg|]}|r|qSr)r
)rrrrr
rAs)
addressurlparseurlsplitparsedr
schemehostpathallowed_request_methodssuppress_http_headers)selfrrrrrr
__init__6szProxy.__init__cCs@|jr(|d|jkr(td||S|jdkr:tj}n&|jdkrLtj}ntd|j	|jf||j
}i}xR|D]F\}}|drx|dd
dd	}|d
ksx||jkrqx|||<qxW|j
|d
<d|kr|d|d<|d
r|d
|d<|drX|ddkr0|dd}tt||d<n&|d|d<t|d}	|d|	}nd}t|d}
|jr|
}|r|ddkr|dd}t|j|}n|
}|dr|d|d7}||d||||}
t|
j}d|
j|
jf}||||
d}	|	dk	r*|
t|	}n|
}| |gS)NREQUEST_METHODZ
DisallowedhttphttpszUnknown scheme for %r: %rHTTP__-rREMOTE_ADDRzx-forwarded-forCONTENT_TYPEzcontent-typeCONTENT_LENGTHz-1z
wsgi.inputzcontent-length	PATH_INFOr/rQUERY_STRING?z%s %s)!rr
rZHTTPBadRequestrhttplibHTTPConnectionHTTPSConnection
ValueErrorrritems
startswithreplacergetreadstrleninturllibquoterrurljoinrequestgetresponse
parse_headersmsgstatusreason	getheaderclose)renvironstart_response	ConnClassconnheaderskeyvaluebodylengthZ	path_infoZrequest_pathrresheaders_outr=rrr
__call__Csh










zProxy.__call__N)rr)__name__
__module____qualname__rrLrrrr
r4s
rr%cCst|}t|}t|||dS)a
    Make a WSGI application that proxies to another address:
    
    ``address``
        the full URL ending with a trailing ``/``
        
    ``allowed_request_methods``:
        a space seperated list of request methods (e.g., ``GET POST``)
        
    ``suppress_http_headers``
        a space seperated list of http headers (lower case, without
        the leading ``http_``) that should not be passed on to target
        host
    )rr)rr)global_confrrrrrr

make_proxysrQc@s*eZdZdZd
ddZddZdd	ZdS)TransparentProxya$
    A proxy that sends the request just as it was given, including
    respecting HTTP_HOST, wsgi.url_scheme, etc.

    This is a way of translating WSGI requests directly to real HTTP
    requests.  All information goes in the environment; modify it to
    modify the way the request is made.

    If you specify ``force_host`` (and optionally ``force_scheme``)
    then HTTP_HOST won't be used to determine where to connect to;
    instead a specific host will be connected to, but the ``Host``
    header in the request will remain intact.
    NrcCs||_||_dS)N)
force_hostforce_scheme)rrSrTrrr
rszTransparentProxy.__init__cCs d|jjtt||j|jfS)Nz%<%s %s force_host=%r force_scheme=%r>)	__class__rMhexidrSrT)rrrr
__repr__s
zTransparentProxy.__repr__cCs|d}|jdkr|}n|j}|dkr.tj}n|dkr>tj}ntd|d|krZtd|d}|jdkrr|}n|j}||}i}	x>|D]2\}
}|
dr|
dd	d	d
}
||	|
<qW||	d<d|krd
|kr|d|	d<|
dr|d|	d<|
dr@t|d}|d|}
|dkr\t
t|
|d<nd|krTd}
d}nd}
d}|
dd|
dd}t|}d|kr|d|d7}||d||
|	|}t|j}d|j|jf}||||d}|dk	r|t|}
n|}
||
gS)Nzwsgi.url_schemerrzUnknown scheme %rZ	HTTP_HOSTz*WSGI environ must contain an HTTP_HOST keyrrrr rr!ZHTTP_X_FORWARDED_FORzx-forwarded-forr"zcontent-typer#z
wsgi.inputr$r%rZSCRIPT_NAMEr&r(r)rz%s %szcontent-length)rSrTr*r+r,r-r.r/r
r0r1r5r2r3r4r6r7r9r:r;r<r=r>r?r@)rrArBrZconn_schemerCrZ	conn_hostrDrErFrGrIrHrrJrKr=rrr
rLsn















zTransparentProxy.__call__)Nr)rMrNrO__doc__rrXrLrrrr
rRs

rRcCsg}x|jD]}|sq|dr^|s2td||\}}|d|}|||fqy|dd\}}Wntd|YnX|}|tkr|||fqW|S)zB
    Turn a Message object into a list of WSGI-style headers.
    rz%First header starts with a space (%r) :rzInvalid header: %r)	rEisspacer-popstripappendsplitr
filtered_headers)messagerKZfull_headerZlast_header
last_valuerGheaderrrr
r;s(
r;rcCst||dS)z
    Create a proxy that connects to a specific host, but does
    absolutely no other filtering, including the Host header.
    )rSrT)rR)rPrSrTrrr
make_transparent_proxysre)r%r%)Nr)rYr*rr6pasterZpaste.util.convertersrraobjectrrQrRr;rerrrr
<module>s
Q
\