##// END OF EJS Templates
fixes problem with basic auth and pushes
marcink -
r1534:72c3cea0 beta
parent child Browse files
Show More
@@ -1,84 +1,86 b''
1 """Pylons middleware initialization"""
1 """Pylons middleware initialization"""
2
2
3 from beaker.middleware import SessionMiddleware
3 from beaker.middleware import SessionMiddleware
4 from routes.middleware import RoutesMiddleware
4 from routes.middleware import RoutesMiddleware
5 from paste.cascade import Cascade
5 from paste.cascade import Cascade
6 from paste.registry import RegistryManager
6 from paste.registry import RegistryManager
7 from paste.urlparser import StaticURLParser
7 from paste.urlparser import StaticURLParser
8 from paste.deploy.converters import asbool
8 from paste.deploy.converters import asbool
9 from paste.gzipper import make_gzip_middleware
9 from paste.gzipper import make_gzip_middleware
10
10
11 from pylons.middleware import ErrorHandler, StatusCodeRedirect
11 from pylons.middleware import ErrorHandler, StatusCodeRedirect
12 from pylons.wsgiapp import PylonsApp
12 from pylons.wsgiapp import PylonsApp
13
13
14 from rhodecode.lib.middleware.simplehg import SimpleHg
14 from rhodecode.lib.middleware.simplehg import SimpleHg
15 from rhodecode.lib.middleware.simplegit import SimpleGit
15 from rhodecode.lib.middleware.simplegit import SimpleGit
16 from rhodecode.lib.middleware.https_fixup import HttpsFixup
16 from rhodecode.lib.middleware.https_fixup import HttpsFixup
17 from rhodecode.config.environment import load_environment
17 from rhodecode.config.environment import load_environment
18
18
19
19
20 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
20 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
21 """Create a Pylons WSGI application and return it
21 """Create a Pylons WSGI application and return it
22
22
23 ``global_conf``
23 ``global_conf``
24 The inherited configuration for this application. Normally from
24 The inherited configuration for this application. Normally from
25 the [DEFAULT] section of the Paste ini file.
25 the [DEFAULT] section of the Paste ini file.
26
26
27 ``full_stack``
27 ``full_stack``
28 Whether or not this application provides a full WSGI stack (by
28 Whether or not this application provides a full WSGI stack (by
29 default, meaning it handles its own exceptions and errors).
29 default, meaning it handles its own exceptions and errors).
30 Disable full_stack when this application is "managed" by
30 Disable full_stack when this application is "managed" by
31 another WSGI middleware.
31 another WSGI middleware.
32
32
33 ``app_conf``
33 ``app_conf``
34 The application's local configuration. Normally specified in
34 The application's local configuration. Normally specified in
35 the [app:<name>] section of the Paste ini file (where <name>
35 the [app:<name>] section of the Paste ini file (where <name>
36 defaults to main).
36 defaults to main).
37
37
38 """
38 """
39 # Configure the Pylons environment
39 # Configure the Pylons environment
40 config = load_environment(global_conf, app_conf)
40 config = load_environment(global_conf, app_conf)
41
41
42 # The Pylons WSGI app
42 # The Pylons WSGI app
43 app = PylonsApp(config=config)
43 app = PylonsApp(config=config)
44
44
45 # Routing/Session/Cache Middleware
45 # Routing/Session/Cache Middleware
46 app = RoutesMiddleware(app, config['routes.map'])
46 app = RoutesMiddleware(app, config['routes.map'])
47 app = SessionMiddleware(app, config)
47 app = SessionMiddleware(app, config)
48
48
49 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
49 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
50 if asbool(config['pdebug']):
50 if asbool(config['pdebug']):
51 from rhodecode.lib.profiler import ProfilingMiddleware
51 from rhodecode.lib.profiler import ProfilingMiddleware
52 app = ProfilingMiddleware(app)
52 app = ProfilingMiddleware(app)
53
53
54
55 # we want our low level middleware to get to the request ASAP. We don't
56 # need any pylons stack middleware in them
57 app = SimpleHg(app, config)
58 app = SimpleGit(app, config)
59
54 if asbool(full_stack):
60 if asbool(full_stack):
55 # Handle Python exceptions
61 # Handle Python exceptions
56 app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
62 app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
57
63
58 # Display error documents for 401, 403, 404 status codes (and
64 # Display error documents for 401, 403, 404 status codes (and
59 # 500 when debug is disabled)
65 # 500 when debug is disabled)
60 if asbool(config['debug']):
66 if asbool(config['debug']):
61 app = StatusCodeRedirect(app)
67 app = StatusCodeRedirect(app)
62 else:
68 else:
63 app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
69 app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
64
70
65 #enable https redirets based on HTTP_X_URL_SCHEME set by proxy
71 #enable https redirets based on HTTP_X_URL_SCHEME set by proxy
66 app = HttpsFixup(app, config)
72 app = HttpsFixup(app, config)
67
73
68 # Establish the Registry for this application
74 # Establish the Registry for this application
69 app = RegistryManager(app)
75 app = RegistryManager(app)
70
76
71 if asbool(static_files):
77 if asbool(static_files):
72 # Serve static files
78 # Serve static files
73 static_app = StaticURLParser(config['pylons.paths']['static_files'])
79 static_app = StaticURLParser(config['pylons.paths']['static_files'])
74 app = Cascade([static_app, app])
80 app = Cascade([static_app, app])
75 app = make_gzip_middleware(app, global_conf, compress_level=1)
81 app = make_gzip_middleware(app, global_conf, compress_level=1)
76
82
77 # we want our low level middleware to get to the request ASAP. We don't
78 # need any pylons stack middleware in them
79 app = SimpleHg(app, config)
80 app = SimpleGit(app, config)
81
83
82 app.config = config
84 app.config = config
83
85
84 return app
86 return app
General Comments 0
You need to be logged in to leave comments. Login now