# HG changeset patch
# Parent 6663d4056caf4d5a1e79323adf12bc5e93ff735d
# User cboos
fcgi: make it possible to use the installed version of flup instead of builtin version.
The environment varialbe TRAC_USE_FLUP needs to be set to `1` in order to force the use of flup.
If `flup` is used, we need to insert some WSGI middleware in order to deal with URL encoding.
diff -r 6663d4056caf trac/web/fcgi_frontend.py
|
a
|
b
|
|
| 15 | 15 | # |
| 16 | 16 | # Author: Matthew Good <trac@matt-good.net> |
| 17 | 17 | |
| | 18 | import os |
| 18 | 19 | import pkg_resources |
| | 20 | import urllib |
| 19 | 21 | |
| 20 | 22 | from trac import __version__ as VERSION |
| 21 | 23 | from trac.web.main import dispatch_request |
| 22 | 24 | |
| 23 | | import _fcgi |
| | 25 | use_flup = os.environ.get('TRAC_USE_FLUP', False) |
| | 26 | if use_flup in ('0', 'no', 'off'): |
| | 27 | use_flup = False |
| | 28 | |
| | 29 | |
| | 30 | class FlupMiddleware(object): |
| | 31 | """Flup doesn't URL unquote the PATH_INFO, so we need to do it.""" |
| | 32 | def __init__(self, application): |
| | 33 | self.application = application |
| | 34 | |
| | 35 | def __call__(self, environ, start_response): |
| | 36 | environ['PATH_INFO'] = urllib.unquote(environ.get('PATH_INFO', '')) |
| | 37 | return self.application(environ, start_response) |
| | 38 | |
| | 39 | params = {} |
| | 40 | |
| | 41 | if use_flup: |
| | 42 | try: |
| | 43 | from flup.server.fcgi import WSGIServer |
| | 44 | params['maxThreads'] = 15 |
| | 45 | dispatch_request = FlupMiddleware(dispatch_request) |
| | 46 | except ImportError: |
| | 47 | use_flup = False |
| | 48 | |
| | 49 | if not use_flup: |
| | 50 | from _fcgi import WSGIServer |
| 24 | 51 | |
| 25 | 52 | def run(): |
| 26 | | _fcgi.WSGIServer(dispatch_request).run() |
| | 53 | WSGIServer(dispatch_request, **params).run() |
| 27 | 54 | |
| 28 | 55 | if __name__ == '__main__': |
| 29 | 56 | pkg_resources.require('Trac==%s' % VERSION) |
diff -r 6663d4056caf trac/web/standalone.py
|
a
|
b
|
|
| 23 | 23 | import os |
| 24 | 24 | import sys |
| 25 | 25 | from SocketServer import ThreadingMixIn |
| 26 | | import urllib |
| 27 | 26 | |
| 28 | 27 | from trac import __version__ as VERSION |
| 29 | 28 | from trac.util import autoreload, daemon |
| … |
… |
|
| 71 | 70 | return self.application(environ, start_response) |
| 72 | 71 | |
| 73 | 72 | |
| 74 | | class FlupMiddleware(object): |
| 75 | | |
| 76 | | def __init__(self, application): |
| 77 | | self.application = application |
| 78 | | |
| 79 | | def __call__(self, environ, start_response): |
| 80 | | environ['PATH_INFO'] = urllib.unquote(environ.get('PATH_INFO', '')) |
| 81 | | return self.application(environ, start_response) |
| 82 | | |
| 83 | | |
| 84 | 73 | class TracEnvironMiddleware(object): |
| 85 | 74 | |
| 86 | 75 | def __init__(self, application, env_parent_dir, env_paths, single_env): |
| … |
… |
|
| 272 | 261 | None, None, ['']).WSGIServer |
| 273 | 262 | flup_app = wsgi_app |
| 274 | 263 | if options.unquote: |
| | 264 | from trac.web.fcgi_frontend import FlupMiddleware |
| 275 | 265 | flup_app = FlupMiddleware(flup_app) |
| 276 | 266 | ret = server_cls(flup_app, bindAddress=server_address).run() |
| 277 | 267 | sys.exit(ret and 42 or 0) # if SIGHUP exit with status 42 |