diff --git a/CHANGELOG b/CHANGELOG index e71e423138..b54aa3d23d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Load WSGI middleware from configuration * Add help text to Dict keys * Update button_action with returned values * Use direct access to backend classes diff --git a/doc/topics/configuration.rst b/doc/topics/configuration.rst index 31d4bca5ae..19a196f665 100644 --- a/doc/topics/configuration.rst +++ b/doc/topics/configuration.rst @@ -462,6 +462,21 @@ It can be overridden for specific models and fields using the names: Default: `''` +wsgi middleware +--------------- + +The section lists the `WSGI middleware`_ class to load. +Each middleware can be configured with a section named `wsgi ` +containing `args` and `kwargs` options. + +Example:: + + [wsgi middleware] + ie = werkzeug.contrib.fixers.InternetExplorerFix + + [wsgi ie] + kwargs={'fix_attach': False} + .. _JSON-RPC: http://en.wikipedia.org/wiki/JSON-RPC .. _XML-RPC: http://en.wikipedia.org/wiki/XML-RPC @@ -470,3 +485,4 @@ Default: `''` .. _SSL: http://en.wikipedia.org/wiki/Secure_Sockets_Layer .. _SSL-CERT: https://docs.python.org/library/ssl.html#ssl.wrap_socket .. _STARTTLS: http://en.wikipedia.org/wiki/STARTTLS +.. _WSGI middleware: https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface#Specification_overview diff --git a/trytond/wsgi.py b/trytond/wsgi.py index c876fcb85e..53fb2ad38b 100644 --- a/trytond/wsgi.py +++ b/trytond/wsgi.py @@ -35,6 +35,7 @@ from trytond.config import config from trytond.protocols.wrappers import Request from trytond.protocols.jsonrpc import JSONProtocol from trytond.protocols.xmlrpc import XMLProtocol +from trytond.tools import resolve __all__ = ['TrytondWSGI', 'app'] @@ -213,5 +214,18 @@ if config.get('web', 'root'): num_proxies = config.getint('web', 'num_proxies') if num_proxies: app.wsgi_app = NumProxyFix(app.wsgi_app, num_proxies) + +if config.has_section('wsgi middleware'): + for middleware in config.options('wsgi middleware'): + Middleware = resolve(config.get('wsgi middleware', middleware)) + args, kwargs = (), {} + section = 'wsgi %s' % middleware + if config.has_section(section): + if config.has_option(section, 'args'): + args = eval(config.get(section, 'args')) + if config.has_option(section, 'kwargs'): + kwargs = eval(config.get(section, 'kwargs')) + app.wsgi_app = Middleware(app.wsgi_app, *args, **kwargs) + import trytond.protocols.dispatcher import trytond.bus