1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
U
Þ=®d™ã@sœdZddlmZddlZddlmZddlmZddlm    Z    ddl
m Z dd    lm Z dd
l mZejrŠdd lmZdd lmZdd lmZGdd„dƒZdS)zt
Basic HTTP Proxy
================
 
.. autoclass:: ProxyMiddleware
 
:copyright: 2007 Pallets
:license: BSD-3-Clause
é)Ú annotationsN)Úclient)Úquote)Úurlsplité)ÚEnvironHeaders)Úis_hop_by_hop_header)Úget_input_stream)Ú StartResponse)ÚWSGIApplication)ÚWSGIEnvironmentc@sNeZdZdZdddddddœd    d
„Zd d d dd œdd„Zddddœdd„ZdS)ÚProxyMiddlewareaÁProxy requests under a path to an external server, routing other
    requests to the app.
 
    This middleware can only proxy HTTP requests, as HTTP is the only
    protocol handled by the WSGI server. Other protocols, such as
    WebSocket requests, cannot be proxied at this layer. This should
    only be used for development, in production a real proxy server
    should be used.
 
    The middleware takes a dict mapping a path prefix to a dict
    describing the host to be proxied to::
 
        app = ProxyMiddleware(app, {
            "/static/": {
                "target": "http://127.0.0.1:5001/",
            }
        })
 
    Each host has the following options:
 
    ``target``:
        The target URL to dispatch to. This is required.
    ``remove_prefix``:
        Whether to remove the prefix from the URL before dispatching it
        to the target. The default is ``False``.
    ``host``:
        ``"<auto>"`` (default):
            The host header is automatically rewritten to the URL of the
            target.
        ``None``:
            The host header is unmodified from the client request.
        Any other value:
            The host header is overwritten with the value.
    ``headers``:
        A dictionary of headers to be sent with the request to the
        target. The default is ``{}``.
    ``ssl_context``:
        A :class:`ssl.SSLContext` defining how to verify requests if the
        target is HTTPS. The default is ``None``.
 
    In the example above, everything under ``"/static/"`` is proxied to
    the server on port 5001. The host header is rewritten to the target,
    and the ``"/static/"`` prefix is removed from the URLs.
 
    :param app: The WSGI application to wrap.
    :param targets: Proxy target configurations. See description above.
    :param chunk_size: Size of chunks to read from input stream and
        write to target.
    :param timeout: Seconds before an operation to a target fails.
 
    .. versionadded:: 0.14
    é@é
r z t.Mapping[str, dict[str, t.Any]]ÚintÚNone)ÚappÚtargetsÚ
chunk_sizeÚtimeoutÚreturncs>dddœdd„‰||_‡fdd„| ¡Dƒ|_||_||_dS)Núdict[str, t.Any])ÚoptsrcSs4| dd¡| dd¡| di¡| dd¡|S)NÚ remove_prefixFÚhostú<auto>ÚheadersÚ ssl_context)Ú
setdefault)r©rúUd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\werkzeug/middleware/http_proxy.pyÚ _set_defaultsXs
    z/ProxyMiddleware.__init__.<locals>._set_defaultscs(i|] \}}d| d¡›dˆ|ƒ“qS)ú/)Ústrip©Ú.0ÚkÚv©r!rr Ú
<dictcomp>`sz,ProxyMiddleware.__init__.<locals>.<dictcomp>)rÚitemsrrr)Úselfrrrrrr(r Ú__init__Qs
ÿzProxyMiddleware.__init__rÚstr)rÚpathÚprefixrcsBtˆdƒ‰ˆj d¡ d¡‰ddddœ‡‡‡‡‡‡fdd    „ }|S)
NÚtargetÚidnaÚasciir r
út.Iterable[bytes]©ÚenvironÚstart_responsercs°tt|ƒ ¡ƒ}dd„|Dƒ|dd…<| d¡ˆddkrL| dˆf¡n2ˆddkrl| d|df¡n| dˆdf¡| ˆd ¡¡ˆ}ˆd    rÈ|tˆƒd… d
¡}ˆj d
¡›d
|›}|     d ¡}d }|d krî| d|f¡n|dk    r| d¡d}z8ˆj
dkr2t j ˆˆj p&dˆjd}n@ˆj
dkr`t jˆˆj pNdˆjˆdd}ntdˆj
›dƒ‚| ¡t|dd}|d}|r¢|›d|›}|j|d|dd|D](\}    }
|     ¡d krÔd!}
| |    |
¡qº| ¡t|ƒ} |  ˆj¡} | s
q6|r(| d"t| ƒ| f¡n
| | ¡qô| ¡‰Wn.tk
rnd#d$lm} | ƒ||ƒYSX|ˆj›d%ˆj ›d&d„ˆ !¡Dƒƒd'd(œ‡‡fd)d*„ }|ƒS)+NcSs,g|]$\}}t|ƒs| ¡dkr||f‘qS))zcontent-lengthr)rÚlowerr$rrr Ú
<listcomp>qs ýzAProxyMiddleware.proxy_to.<locals>.application.<locals>.<listcomp>)Ú
ConnectionÚcloserrÚHostZ    HTTP_HOSTrrr"ÚCONTENT_LENGTHF)ÚNzContent-Length)zTransfer-EncodingÚchunkedTÚhttpéP)rÚhttpsi»r)rÚcontextz-Target scheme must be 'http' or 'https', got Ú.z!$&'()*+,/:;=@%)ÚsafeÚ QUERY_STRINGú?ÚREQUEST_METHOD)Ú    skip_hostÚ
connectionr:s%x
%s
r)Ú
BadGatewayú cSs$g|]\}}t|ƒs| ¡|f‘qSr)rÚtitler$rrr r8Ésþzt.Iterator[bytes])rc3s<zˆ ˆj¡}Wntk
r(Yq8YnX|s0q8|VqdS)N)ÚreadrÚOSError)Údata)Úrespr+rr rMÐs
z;ProxyMiddleware.proxy_to.<locals>.application.<locals>.read)"Úlistrr*ÚappendÚextendÚlenÚlstripr.ÚrstripÚgetÚschemerÚHTTPConnectionÚportrÚHTTPSConnectionÚ RuntimeErrorÚconnectrÚ
putrequestr7Ú    putheaderÚ
endheadersr    rMrÚsendÚ getresponserNÚ
exceptionsrJÚstatusÚreasonÚ
getheaders)r5r6rZ remote_pathÚcontent_lengthr>ÚconÚ
remote_urlZ querystringr&r'ÚstreamrOrJrM©rrr.r/r+r0)rPr Ú applicationmsŠþ
 
 
 
 
ÿ 
ü ÿ     þþ     z-ProxyMiddleware.proxy_to.<locals>.application)rÚhostnameÚencodeÚdecode)r+rr.r/rlrrkr Úproxy_tofs  qzProxyMiddleware.proxy_tor r
r3r4cCsH|d}|j}|j ¡D]$\}}| |¡r| |||¡}q>q|||ƒS)NZ    PATH_INFO)rrr*Ú
startswithrp)r+r5r6r.rr/rrrr Ú__call__às
zProxyMiddleware.__call__N)rr)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r,rprrrrrr r s 9ûzr )rvÚ
__future__rÚtypingÚtr?rÚ urllib.parserrZdatastructuresrrZwsgir    Ú TYPE_CHECKINGZ_typeshed.wsgir
r r r rrrr Ú<module>s