changeset b108dd82df17 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=b108dd82df17
description:
Load WSGI middleware from configuration
issue8807
review270521002
diffstat:
CHANGELOG | 1 +
doc/topics/configuration.rst | 16 ++++++++++++++++
trytond/wsgi.py | 14 ++++++++++++++
3 files changed, 31 insertions(+), 0 deletions(-)
diffs (68 lines):
diff -r 0fc4a0dec30d -r b108dd82df17 CHANGELOG
--- a/CHANGELOG Thu Dec 19 17:36:26 2019 +0100
+++ b/CHANGELOG Sat Dec 28 18:00:01 2019 +0100
@@ -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 -r 0fc4a0dec30d -r b108dd82df17 doc/topics/configuration.rst
--- a/doc/topics/configuration.rst Thu Dec 19 17:36:26 2019 +0100
+++ b/doc/topics/configuration.rst Sat Dec 28 18:00:01 2019 +0100
@@ -462,6 +462,21 @@
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 @@
.. _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 -r 0fc4a0dec30d -r b108dd82df17 trytond/wsgi.py
--- a/trytond/wsgi.py Thu Dec 19 17:36:26 2019 +0100
+++ b/trytond/wsgi.py Sat Dec 28 18:00:01 2019 +0100
@@ -35,6 +35,7 @@
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 @@
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