class ProxyFix: (source)
Adjust the WSGI environ based on ``X-Forwarded-`` that proxies in front of the application may set. - ``X-Forwarded-For`` sets ``REMOTE_ADDR``. - ``X-Forwarded-Proto`` sets ``wsgi.url_scheme``. - ``X-Forwarded-Host`` sets ``HTTP_HOST``, ``SERVER_NAME``, and ``SERVER_PORT``. - ``X-Forwarded-Port`` sets ``HTTP_HOST`` and ``SERVER_PORT``. - ``X-Forwarded-Prefix`` sets ``SCRIPT_NAME``. 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. :param app: The WSGI application to wrap. :param x_for: Number of values to trust for ``X-Forwarded-For``. :param x_proto: Number of values to trust for ``X-Forwarded-Proto``. :param x_host: Number of values to trust for ``X-Forwarded-Host``. :param x_port: Number of values to trust for ``X-Forwarded-Port``. :param x_prefix: Number of values to trust for ``X-Forwarded-Prefix``. .. code-block:: python 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) .. versionchanged:: 1.0 Deprecated code has been removed: * The ``num_proxies`` argument and attribute. * The ``get_remote_addr`` method. * The environ keys ``orig_remote_addr``, ``orig_wsgi_url_scheme``, and ``orig_http_host``. .. versionchanged:: 0.15 All headers support multiple values. The ``num_proxies`` argument is deprecated. Each header is configured with a separate number of trusted proxies. .. versionchanged:: 0.15 Original WSGI environ values are stored in the ``werkzeug.proxy_fix.orig`` dict. ``orig_remote_addr``, ``orig_wsgi_url_scheme``, and ``orig_http_host`` are deprecated and will be removed in 1.0. .. versionchanged:: 0.15 Support ``X-Forwarded-Port`` and ``X-Forwarded-Prefix``. .. versionchanged:: 0.15 ``X-Forwarded-Host`` and ``X-Forwarded-Port`` modify ``SERVER_NAME`` and ``SERVER_PORT``.
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 |
Undocumented |
Instance Variable | x |
Undocumented |
Instance Variable | x |
Undocumented |
Instance Variable | x |
Undocumented |
Instance Variable | x |
Undocumented |
Method | _get |
Get the real value from a list header based on the configured number of trusted proxies. |
WSGIEnvironment
, start_response: StartResponse
) -> t.Iterable[ bytes]
:
(source)
¶
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}``.
WSGIApplication
, x_for: int
= 1, x_proto: int
= 1, x_host: int
= 0, x_port: int
= 0, x_prefix: int
= 0):
(source)
¶
Undocumented
Get the real value from a list header based on the configured number of trusted proxies. :param trusted: Number of values to trust in the header. :param value: Comma separated list header value to parse. :return: The real value, or ``None`` if there are fewer values than the number of trusted proxies. .. versionchanged:: 1.0 Renamed from ``_get_trusted_comma``. .. versionadded:: 0.15