~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to serve-branches

  • Committer: Michael Hudson
  • Date: 2009-02-04 22:41:28 UTC
  • Revision ID: michael.hudson@canonical.com-20090204224128-x6zbokdi5gn8u88w
error if you run serve-branches behind proxy when paste.deploy is not available

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from optparse import OptionParser
23
23
 
24
24
from paste import httpserver
25
 
from paste.httpexceptions import HTTPExceptionHandler
 
25
from paste.httpexceptions import HTTPExceptionHandler, HTTPInternalServerError
26
26
from paste.translogger import TransLogger
27
27
 
28
28
from loggerhead import __version__
116
116
    logfile.setLevel(logging.DEBUG)
117
117
    logger.addHandler(logfile)
118
118
    # setup_logging() #end
119
 
    app = ErrorHandlerApp(app)
120
 
    app = HTTPExceptionHandler(app)
121
119
    app = TransLogger(app, logger=logger)
122
120
    if options.profile:
123
121
        from loggerhead.middleware.profile import LSProfMiddleware
131
129
    try:
132
130
        from paste.deploy.config import PrefixMiddleware
133
131
    except ImportError:
134
 
        pass
 
132
        cant_proxy_correctly_message = (
 
133
            'Unsupported configuration: PasteDeploy not available, but '
 
134
            'loggerhead appears to be behind a proxy.')
 
135
        def check_not_proxied(app):
 
136
            def wrapped(environ, start_response):
 
137
                if 'HTTP_X_FORWARDED_SERVER' in environ:
 
138
                    exc = HTTPInternalServerError()
 
139
                    exc.explanation = cant_proxy_correctly_message
 
140
                    raise exc
 
141
                return app(environ, start_response)
 
142
            return wrapped
 
143
        app = check_not_proxied(app)
135
144
    else:
136
145
        app = PrefixMiddleware(app, prefix=prefix)
137
146
 
 
147
    app = ErrorHandlerApp(app)
 
148
    app = HTTPExceptionHandler(app)
 
149
 
138
150
    if not options.user_port:
139
151
        port = '8080'
140
152
    else: