22
22
from optparse import OptionParser
24
from bzrlib.plugin import load_plugins
24
26
from paste import httpserver
25
from paste.httpexceptions import HTTPExceptionHandler
27
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
26
28
from paste.translogger import TransLogger
28
30
from loggerhead import __version__
50
52
help="Host Loggerhead should listen on.")
51
53
parser.add_option("--prefix", dest="user_prefix",
52
54
help="Specify host prefix.")
55
parser.add_option("--profile", action="store_true", dest="profile",
56
help="Generate callgrind profile data to "
57
"%d-stats.callgrind on each request.")
53
58
parser.add_option("--reload", action="store_true", dest="reload",
54
59
help="Restarts the application when changing python"
55
60
" files. Only used for development purposes.")
113
118
logfile.setLevel(logging.DEBUG)
114
119
logger.addHandler(logfile)
115
120
# setup_logging() #end
116
app = ErrorHandlerApp(app)
117
app = HTTPExceptionHandler(app)
118
121
app = TransLogger(app, logger=logger)
123
from loggerhead.middleware.profile import LSProfMiddleware
124
app = LSProfMiddleware(app)
120
126
if not options.user_prefix:
123
129
prefix = options.user_prefix
130
if not prefix.startswith('/'):
131
prefix = '/' + prefix
126
134
from paste.deploy.config import PrefixMiddleware
127
135
except ImportError:
136
cant_proxy_correctly_message = (
137
'Unsupported configuration: PasteDeploy not available, but '
138
'loggerhead appears to be behind a proxy.')
139
def check_not_proxied(app):
140
def wrapped(environ, start_response):
141
if 'HTTP_X_FORWARDED_SERVER' in environ:
142
exc = HTTPInternalServerError()
143
exc.explanation = cant_proxy_correctly_message
145
return app(environ, start_response)
147
app = check_not_proxied(app)
130
149
app = PrefixMiddleware(app, prefix=prefix)
151
app = HTTPExceptionHandler(app)
152
app = ErrorHandlerApp(app)
132
154
if not options.user_port: