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