Load WSGI middleware from configuration

issue8807
review270521002
This commit is contained in:
Cédric Krier
2019-12-28 18:00:01 +01:00
parent 45226af9d5
commit 35fec78c17
3 changed files with 31 additions and 0 deletions
+1
View File
@@ -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
+16
View File
@@ -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 <middleware>`
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
+14
View File
@@ -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