OpenQuizz
Une application de gestion des contenus pédagogiques
ProxyFix Class Reference
Inheritance diagram for ProxyFix:
Collaboration diagram for ProxyFix:

Public Member Functions

def __init__ (self, app, x_for=1, x_proto=1, x_host=0, x_port=0, x_prefix=0)
 
def __call__ (self, environ, start_response)
 

Data Fields

 app
 
 x_for
 
 x_proto
 
 x_host
 
 x_port
 
 x_prefix
 

Detailed Description

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``.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  app,
  x_for = 1,
  x_proto = 1,
  x_host = 0,
  x_port = 0,
  x_prefix = 0 
)

Member Function Documentation

◆ __call__()

def __call__ (   self,
  environ,
  start_response 
)
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}``.

Field Documentation

◆ app

app

◆ x_for

x_for

◆ x_host

x_host

◆ x_port

x_port

◆ x_prefix

x_prefix

◆ x_proto

x_proto

The documentation for this class was generated from the following file: