Mercurial > kallithea
changeset 8549:d757635af3c2
tg: include the Kallithea middleware wrapping of the TG WSGI application in application.py
This seems to make the architecture more clear than using hooks.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Fri, 24 Apr 2020 13:32:17 +0200 |
parents | 27d9ca0c8381 |
children | 6b01e99bdb2b |
files | kallithea/config/app_cfg.py kallithea/config/application.py |
diffstat | 2 files changed, 29 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/config/app_cfg.py Fri Apr 24 13:17:00 2020 +0200 +++ b/kallithea/config/app_cfg.py Fri Apr 24 13:32:17 2020 +0200 @@ -34,11 +34,6 @@ import kallithea.model.base import kallithea.model.meta from kallithea.lib import celerypylons -from kallithea.lib.middleware.https_fixup import HttpsFixup -from kallithea.lib.middleware.permanent_repo_url import PermanentRepoUrl -from kallithea.lib.middleware.simplegit import SimpleGit -from kallithea.lib.middleware.simplehg import SimpleHg -from kallithea.lib.middleware.wrapper import RequestWrapper from kallithea.lib.utils import check_git_version, load_rcextensions, set_app_settings, set_indexer_config, set_vcs_config from kallithea.lib.utils2 import asbool from kallithea.model import db @@ -168,27 +163,3 @@ tg.hooks.register('configure_new_app', setup_configuration) - - -def setup_application(app): - config = app.config - - # we want our low level middleware to get to the request ASAP. We don't - # need any stack middleware in them - especially no StatusCodeRedirect buffering - app = SimpleHg(app, config) - app = SimpleGit(app, config) - - # Enable https redirects based on HTTP_X_URL_SCHEME set by proxy - if any(asbool(config.get(x)) for x in ['https_fixup', 'force_https', 'use_htsts']): - app = HttpsFixup(app, config) - - app = PermanentRepoUrl(app, config) - - # Optional and undocumented wrapper - gives more verbose request/response logging, but has a slight overhead - if asbool(config.get('use_wsgi_wrapper')): - app = RequestWrapper(app, config) - - return app - - -tg.hooks.register('before_wsgi_middlewares', setup_application)
--- a/kallithea/config/application.py Fri Apr 24 13:17:00 2020 +0200 +++ b/kallithea/config/application.py Fri Apr 24 13:32:17 2020 +0200 @@ -14,11 +14,39 @@ """WSGI middleware initialization for the Kallithea application.""" from kallithea.config.app_cfg import base_config +from kallithea.lib.middleware.https_fixup import HttpsFixup +from kallithea.lib.middleware.permanent_repo_url import PermanentRepoUrl +from kallithea.lib.middleware.simplegit import SimpleGit +from kallithea.lib.middleware.simplehg import SimpleHg +from kallithea.lib.middleware.wrapper import RequestWrapper +from kallithea.lib.utils2 import asbool __all__ = ['make_app'] +def wrap_app(app): + """Wrap the TG WSGI application in Kallithea middleware""" + config = app.config + + # we want our low level middleware to get to the request ASAP. We don't + # need any stack middleware in them - especially no StatusCodeRedirect buffering + app = SimpleHg(app, config) + app = SimpleGit(app, config) + + # Enable https redirects based on HTTP_X_URL_SCHEME set by proxy + if any(asbool(config.get(x)) for x in ['https_fixup', 'force_https', 'use_htsts']): + app = HttpsFixup(app, config) + + app = PermanentRepoUrl(app, config) + + # Optional and undocumented wrapper - gives more verbose request/response logging, but has a slight overhead + if asbool(config.get('use_wsgi_wrapper')): + app = RequestWrapper(app, config) + + return app + + def make_app(global_conf, **app_conf): """ Set up Kallithea with the settings found in the PasteDeploy configuration @@ -37,4 +65,4 @@ assert app_conf.get('sqlalchemy.url') # must be called with a Kallithea .ini file, which for example must have this config option assert global_conf.get('here') and global_conf.get('__file__') # app config should be initialized the paste way ... - return base_config.make_wsgi_app(global_conf, app_conf, wrap_app=None) + return base_config.make_wsgi_app(global_conf, app_conf, wrap_app=wrap_app)