Created
July 2, 2017 22:17
-
-
Save dwoz/77fbbe7eed0c1695871f1500b3dcc1f1 to your computer and use it in GitHub Desktop.
Configure profiler via Apache's SetEvn directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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