##// END OF EJS Templates
middleware: fix url_scheme_variable...
Mads Kiilerich -
r8716:ed117efc stable
parent child Browse files
Show More
@@ -1,68 +1,68 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # This program is free software: you can redistribute it and/or modify
2 # This program is free software: you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation, either version 3 of the License, or
4 # the Free Software Foundation, either version 3 of the License, or
5 # (at your option) any later version.
5 # (at your option) any later version.
6 #
6 #
7 # This program is distributed in the hope that it will be useful,
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
10 # GNU General Public License for more details.
11 #
11 #
12 # You should have received a copy of the GNU General Public License
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """WSGI middleware initialization for the Kallithea application."""
14 """WSGI middleware initialization for the Kallithea application."""
15
15
16 from kallithea.config.app_cfg import base_config
16 from kallithea.config.app_cfg import base_config
17 from kallithea.config.middleware.https_fixup import HttpsFixup
17 from kallithea.config.middleware.https_fixup import HttpsFixup
18 from kallithea.config.middleware.permanent_repo_url import PermanentRepoUrl
18 from kallithea.config.middleware.permanent_repo_url import PermanentRepoUrl
19 from kallithea.config.middleware.simplegit import SimpleGit
19 from kallithea.config.middleware.simplegit import SimpleGit
20 from kallithea.config.middleware.simplehg import SimpleHg
20 from kallithea.config.middleware.simplehg import SimpleHg
21 from kallithea.config.middleware.wrapper import RequestWrapper
21 from kallithea.config.middleware.wrapper import RequestWrapper
22 from kallithea.lib.utils2 import asbool
22 from kallithea.lib.utils2 import asbool
23
23
24
24
25 __all__ = ['make_app']
25 __all__ = ['make_app']
26
26
27
27
28 def wrap_app(app):
28 def wrap_app(app):
29 """Wrap the TG WSGI application in Kallithea middleware"""
29 """Wrap the TG WSGI application in Kallithea middleware"""
30 config = app.config
30 config = app.config
31
31
32 # we want our low level middleware to get to the request ASAP. We don't
32 # we want our low level middleware to get to the request ASAP. We don't
33 # need any stack middleware in them - especially no StatusCodeRedirect buffering
33 # need any stack middleware in them - especially no StatusCodeRedirect buffering
34 app = SimpleHg(app, config)
34 app = SimpleHg(app, config)
35 app = SimpleGit(app, config)
35 app = SimpleGit(app, config)
36
36
37 # Enable https redirects based on HTTP_X_URL_SCHEME set by proxy
37 # Enable https redirects based on HTTP_X_URL_SCHEME set by proxy
38 if any(asbool(config.get(x)) for x in ['url_scheme_variable', 'force_https', 'use_htsts']):
38 if config.get('url_scheme_variable') or asbool(config.get('force_https')) or asbool(config.get('use_htsts')):
39 app = HttpsFixup(app, config)
39 app = HttpsFixup(app, config)
40
40
41 app = PermanentRepoUrl(app, config)
41 app = PermanentRepoUrl(app, config)
42
42
43 # Optional and undocumented wrapper - gives more verbose request/response logging, but has a slight overhead
43 # Optional and undocumented wrapper - gives more verbose request/response logging, but has a slight overhead
44 if asbool(config.get('use_wsgi_wrapper')):
44 if asbool(config.get('use_wsgi_wrapper')):
45 app = RequestWrapper(app, config)
45 app = RequestWrapper(app, config)
46
46
47 return app
47 return app
48
48
49
49
50 def make_app(global_conf, **app_conf):
50 def make_app(global_conf, **app_conf):
51 """
51 """
52 Set up Kallithea with the settings found in the PasteDeploy configuration
52 Set up Kallithea with the settings found in the PasteDeploy configuration
53 file used.
53 file used.
54
54
55 :param global_conf: The global settings for Kallithea (those
55 :param global_conf: The global settings for Kallithea (those
56 defined under the ``[DEFAULT]`` section).
56 defined under the ``[DEFAULT]`` section).
57 :return: The Kallithea application with all the relevant middleware
57 :return: The Kallithea application with all the relevant middleware
58 loaded.
58 loaded.
59
59
60 This is the PasteDeploy factory for the Kallithea application.
60 This is the PasteDeploy factory for the Kallithea application.
61
61
62 ``app_conf`` contains all the application-specific settings (those defined
62 ``app_conf`` contains all the application-specific settings (those defined
63 under ``[app:main]``.
63 under ``[app:main]``.
64 """
64 """
65 assert app_conf.get('sqlalchemy.url') # must be called with a Kallithea .ini file, which for example must have this config option
65 assert app_conf.get('sqlalchemy.url') # must be called with a Kallithea .ini file, which for example must have this config option
66 assert global_conf.get('here') and global_conf.get('__file__') # app config should be initialized the paste way ...
66 assert global_conf.get('here') and global_conf.get('__file__') # app config should be initialized the paste way ...
67
67
68 return base_config.make_wsgi_app(global_conf, app_conf, wrap_app=wrap_app)
68 return base_config.make_wsgi_app(global_conf, app_conf, wrap_app=wrap_app)
General Comments 0
You need to be logged in to leave comments. Login now