Mercurial > kallithea
annotate rhodecode/config/middleware.py @ 3503:7adeca7b99c2 beta
root.html: IE do not like extra ',' in maps
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 07 Mar 2013 15:23:36 +0100 |
parents | d997a314d18a |
children | e1568c0bac1f |
rev | line source |
---|---|
0 | 1 """Pylons middleware initialization""" |
1018
da5075ce681c
rhodecode config module refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
2 |
43 | 3 from beaker.middleware import SessionMiddleware |
1018
da5075ce681c
rhodecode config module refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
4 from routes.middleware import RoutesMiddleware |
0 | 5 from paste.cascade import Cascade |
6 from paste.registry import RegistryManager | |
7 from paste.urlparser import StaticURLParser | |
8 from paste.deploy.converters import asbool | |
1018
da5075ce681c
rhodecode config module refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
9 from paste.gzipper import make_gzip_middleware |
da5075ce681c
rhodecode config module refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
10 |
0 | 11 from pylons.middleware import ErrorHandler, StatusCodeRedirect |
12 from pylons.wsgiapp import PylonsApp | |
1018
da5075ce681c
rhodecode config module refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
914
diff
changeset
|
13 |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
14 from rhodecode.lib.middleware.simplehg import SimpleHg |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
15 from rhodecode.lib.middleware.simplegit import SimpleGit |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
16 from rhodecode.lib.middleware.https_fixup import HttpsFixup |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
17 from rhodecode.config.environment import load_environment |
3489
d997a314d18a
moved time measure of request to separate middleware for better results (the last one in stack)
Marcin Kuzminski <marcin@python-works.com>
parents:
2939
diff
changeset
|
18 from rhodecode.lib.middleware.wrapper import RequestWrapper |
12 | 19 |
1205
f4807acf643d
added __license__ into main of rhodecode, PEP8ify
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
20 |
43 | 21 def make_app(global_conf, full_stack=True, static_files=True, **app_conf): |
0 | 22 """Create a Pylons WSGI application and return it |
23 | |
24 ``global_conf`` | |
25 The inherited configuration for this application. Normally from | |
26 the [DEFAULT] section of the Paste ini file. | |
27 | |
28 ``full_stack`` | |
12 | 29 Whether or not this application provides a full WSGI stack (by |
30 default, meaning it handles its own exceptions and errors). | |
31 Disable full_stack when this application is "managed" by | |
32 another WSGI middleware. | |
0 | 33 |
34 ``app_conf`` | |
35 The application's local configuration. Normally specified in | |
36 the [app:<name>] section of the Paste ini file (where <name> | |
37 defaults to main). | |
38 | |
39 """ | |
40 # Configure the Pylons environment | |
43 | 41 config = load_environment(global_conf, app_conf) |
42 | |
0 | 43 # The Pylons WSGI app |
43 | 44 app = PylonsApp(config=config) |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
45 |
0 | 46 # Routing/Session/Cache Middleware |
47 app = RoutesMiddleware(app, config['routes.map']) | |
21 | 48 app = SessionMiddleware(app, config) |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
49 |
204
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
203
diff
changeset
|
50 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) |
1355
bfc529377cdc
added simple profiling middleware controlled by .ini file flag
Marcin Kuzminski <marcin@python-works.com>
parents:
1205
diff
changeset
|
51 if asbool(config['pdebug']): |
bfc529377cdc
added simple profiling middleware controlled by .ini file flag
Marcin Kuzminski <marcin@python-works.com>
parents:
1205
diff
changeset
|
52 from rhodecode.lib.profiler import ProfilingMiddleware |
bfc529377cdc
added simple profiling middleware controlled by .ini file flag
Marcin Kuzminski <marcin@python-works.com>
parents:
1205
diff
changeset
|
53 app = ProfilingMiddleware(app) |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
54 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1696
diff
changeset
|
55 if asbool(full_stack): |
1534
72c3cea0175a
fixes problem with basic auth and pushes
Marcin Kuzminski <marcin@python-works.com>
parents:
1496
diff
changeset
|
56 |
2939
dbe3cfb81446
Added Errormator and Sentry support part of pull request #71
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
57 from rhodecode.lib.middleware.sentry import Sentry |
dbe3cfb81446
Added Errormator and Sentry support part of pull request #71
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
58 from rhodecode.lib.middleware.errormator import Errormator |
dbe3cfb81446
Added Errormator and Sentry support part of pull request #71
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
59 if Errormator: |
dbe3cfb81446
Added Errormator and Sentry support part of pull request #71
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
60 app = Errormator(app, config) |
dbe3cfb81446
Added Errormator and Sentry support part of pull request #71
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
61 elif Sentry: |
dbe3cfb81446
Added Errormator and Sentry support part of pull request #71
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
62 app = Sentry(app, config) |
dbe3cfb81446
Added Errormator and Sentry support part of pull request #71
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
63 |
0 | 64 # Handle Python exceptions |
65 app = ErrorHandler(app, global_conf, **config['pylons.errorware']) | |
66 | |
1696
2d85e969d78a
overcomes git push issues with errormiddleware and debug off
Marcin Kuzminski <marcin@python-works.com>
parents:
1534
diff
changeset
|
67 # we want our low level middleware to get to the request ASAP. We don't |
2d85e969d78a
overcomes git push issues with errormiddleware and debug off
Marcin Kuzminski <marcin@python-works.com>
parents:
1534
diff
changeset
|
68 # need any pylons stack middleware in them |
2d85e969d78a
overcomes git push issues with errormiddleware and debug off
Marcin Kuzminski <marcin@python-works.com>
parents:
1534
diff
changeset
|
69 app = SimpleHg(app, config) |
2d85e969d78a
overcomes git push issues with errormiddleware and debug off
Marcin Kuzminski <marcin@python-works.com>
parents:
1534
diff
changeset
|
70 app = SimpleGit(app, config) |
3489
d997a314d18a
moved time measure of request to separate middleware for better results (the last one in stack)
Marcin Kuzminski <marcin@python-works.com>
parents:
2939
diff
changeset
|
71 app = RequestWrapper(app, config) |
0 | 72 # Display error documents for 401, 403, 404 status codes (and |
73 # 500 when debug is disabled) | |
74 if asbool(config['debug']): | |
86
e47d1db5ef20
Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
75 app = StatusCodeRedirect(app) |
0 | 76 else: |
86
e47d1db5ef20
Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
77 app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
78 |
216
c8162373f214
Cleaned the way based was used to generate submenu for admin, now it's much more clear to use submenu. Cleaned admin and added comment to middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
207
diff
changeset
|
79 #enable https redirets based on HTTP_X_URL_SCHEME set by proxy |
914
110a00c181de
Added force https option into config files
Marcin Kuzminski <marcin@python-works.com>
parents:
702
diff
changeset
|
80 app = HttpsFixup(app, config) |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
81 |
0 | 82 # Establish the Registry for this application |
83 app = RegistryManager(app) | |
84 | |
43 | 85 if asbool(static_files): |
86 # Serve static files | |
87 static_app = StaticURLParser(config['pylons.paths']['static_files']) | |
88 app = Cascade([static_app, app]) | |
702
a9158dfa05cc
added gzip middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
635
diff
changeset
|
89 app = make_gzip_middleware(app, global_conf, compress_level=1) |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
90 |
269
183c06406127
fixed bug in middleware config
Marcin Kuzminski <marcin@python-works.com>
parents:
216
diff
changeset
|
91 app.config = config |
43 | 92 |
12 | 93 return app |