Mercurial > kallithea
annotate rhodecode/config/middleware.py @ 1209:45fed9a435b7
merges for upcoming release
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 05 Apr 2011 12:08:34 +0200 |
parents | af6ca51fb80f |
children | bf263968da47 |
rev | line source |
---|---|
0 | 1 """Pylons middleware initialization""" |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
923
diff
changeset
|
2 |
43 | 3 from beaker.middleware import SessionMiddleware |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
923
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 | |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
923
diff
changeset
|
9 from paste.gzipper import make_gzip_middleware |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
923
diff
changeset
|
10 |
0 | 11 from pylons.middleware import ErrorHandler, StatusCodeRedirect |
12 from pylons.wsgiapp import PylonsApp | |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
923
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 |
12 | 18 |
1209
45fed9a435b7
merges for upcoming release
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
19 |
43 | 20 def make_app(global_conf, full_stack=True, static_files=True, **app_conf): |
0 | 21 """Create a Pylons WSGI application and return it |
22 | |
23 ``global_conf`` | |
24 The inherited configuration for this application. Normally from | |
25 the [DEFAULT] section of the Paste ini file. | |
26 | |
27 ``full_stack`` | |
12 | 28 Whether or not this application provides a full WSGI stack (by |
29 default, meaning it handles its own exceptions and errors). | |
30 Disable full_stack when this application is "managed" by | |
31 another WSGI middleware. | |
0 | 32 |
33 ``app_conf`` | |
34 The application's local configuration. Normally specified in | |
35 the [app:<name>] section of the Paste ini file (where <name> | |
36 defaults to main). | |
37 | |
38 """ | |
39 # Configure the Pylons environment | |
43 | 40 config = load_environment(global_conf, app_conf) |
41 | |
0 | 42 # The Pylons WSGI app |
43 | 43 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
|
44 |
0 | 45 # Routing/Session/Cache Middleware |
46 app = RoutesMiddleware(app, config['routes.map']) | |
21 | 47 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
|
48 |
204
a8ea3ce3cdc4
Created middleware package. Crated special middleware to handle https requests redirections.
Marcin Kuzminski <marcin@python-works.com>
parents:
203
diff
changeset
|
49 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
50 |
101
8b06c420491d
statics moved to pylons.
Marcin Kuzminski <marcin@python-works.com>
parents:
86
diff
changeset
|
51 app = SimpleHg(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
|
52 app = SimpleGit(app, config) |
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
53 |
0 | 54 if asbool(full_stack): |
55 # Handle Python exceptions | |
56 app = ErrorHandler(app, global_conf, **config['pylons.errorware']) | |
57 | |
58 # Display error documents for 401, 403, 404 status codes (and | |
59 # 500 when debug is disabled) | |
60 if asbool(config['debug']): | |
86
e47d1db5ef20
Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
61 app = StatusCodeRedirect(app) |
0 | 62 else: |
86
e47d1db5ef20
Added few options to configs,
Marcin Kuzminski <marcin@python-blog.com>
parents:
49
diff
changeset
|
63 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
|
64 |
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
|
65 #enable https redirets based on HTTP_X_URL_SCHEME set by proxy |
923
7e9c80b515af
fixed middleware for new https fixup
Marcin Kuzminski <marcin@python-works.com>
parents:
702
diff
changeset
|
66 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
|
67 |
0 | 68 # Establish the Registry for this application |
69 app = RegistryManager(app) | |
70 | |
43 | 71 if asbool(static_files): |
72 # Serve static files | |
73 static_app = StaticURLParser(config['pylons.paths']['static_files']) | |
74 app = Cascade([static_app, app]) | |
702
a9158dfa05cc
added gzip middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
635
diff
changeset
|
75 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
|
76 |
269
183c06406127
fixed bug in middleware config
Marcin Kuzminski <marcin@python-works.com>
parents:
216
diff
changeset
|
77 app.config = config |
43 | 78 |
12 | 79 return app |