Skip to content

Instantly share code, notes, and snippets.

@dwoz
Created July 2, 2017 22:17
Show Gist options
  • Save dwoz/77fbbe7eed0c1695871f1500b3dcc1f1 to your computer and use it in GitHub Desktop.
Save dwoz/77fbbe7eed0c1695871f1500b3dcc1f1 to your computer and use it in GitHub Desktop.
Configure profiler via Apache's SetEvn directive
'''
Configure profiler via Apache's SetEvn directive
'''
class Profiler(object):
'''
Simple wrapper around werkzeug's ProfilerMiddleware. This allow enabling
the profile via apache's SetEnv directive:
SetEnv WSGI_PROFILER Yes
'''
def __init__(self, app, enabled=False):
self._app = app
self._wsgi_app = self._app.wsgi_app
self.enabled = enabled
def __call__(self, environ, start_response):
if environ.get('WSGI_PROFILER', 'No') != 'No':
self.enabled = True
if self.enabled:
from werkzeug.contrib.profiler import ProfilerMiddleware
self._wsgi_app = ProfilerMiddleware(self._wsgi_app)
self._app.debug = True
return self._wsgi_app(environ, start_response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment