class ProxyFix:
Adjust the WSGI environ based on X-Forwarded- that proxies in front of the application may set.
You must tell the middleware how many proxies set each header so it knows what values to trust. It is a security issue to trust values that came from the client rather than a proxy.
The original values of the headers are stored in the WSGI environ as werkzeug.proxy_fix.orig, a dict.
from werkzeug.middleware.proxy_fix import ProxyFix # App is behind one proxy that sets the -For and -Host headers. app = ProxyFix(app, x_for=1, x_host=1)
Changed in version 1.0: Deprecated code has been removed:
Parameters | |
app | The WSGI application to wrap. |
x_for | Number of values to trust for X-Forwarded-For. |
x_proto | Number of values to trust for X-Forwarded-Proto. |
x_host | Number of values to trust for X-Forwarded-Host. |
x_port | Number of values to trust for X-Forwarded-Port. |
x_prefix | Number of values to trust for X-Forwarded-Prefix. |
Method | __call__ |
Modify the WSGI environ based on the various Forwarded headers before calling the wrapped application. Store the original environ values in werkzeug.proxy_fix.orig_{key}. |
Method | __init__ |
Undocumented |
Instance Variable | app |
Undocumented |
Instance Variable | x_for |
Undocumented |
Instance Variable | x_host |
Undocumented |
Instance Variable | x_port |
Undocumented |
Instance Variable | x_prefix |
Undocumented |
Instance Variable | x_proto |
Undocumented |
Method | _get_real_value |
Get the real value from a list header based on the configured number of trusted proxies. |
Parameters | |
environ:WSGIEnvironment | Undocumented |
start_response:StartResponse | Undocumented |
Returns | |
t.Iterable[ | Undocumented |
Undocumented
Parameters | |
app:WSGIApplication | Undocumented |
x_for:int | Undocumented |
x_proto:int | Undocumented |
x_host:int | Undocumented |
x_port:int | Undocumented |
x_prefix:int | Undocumented |
Get the real value from a list header based on the configured number of trusted proxies.
Parameters | |
trusted:int | Number of values to trust in the header. |
value:t.Optional[ | Comma separated list header value to parse. |
Returns | |
t.Optional[ | The real value, or None if there are fewer values than the number of trusted proxies. |