Changeset - a8ea3ce3cdc4
[Not reviewed]
default
2 1 3
Marcin Kuzminski - 15 years ago 2010-05-23 00:54:22
marcin@python-works.com
Created middleware package. Crated special middleware to handle https requests redirections.
5 files changed with 25 insertions and 29 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/middleware.py
Show inline comments
 
@@ -4,13 +4,14 @@ from paste.cascade import Cascade
 
from paste.registry import RegistryManager
 
from paste.urlparser import StaticURLParser
 
from paste.deploy.converters import asbool
 
from pylons.middleware import ErrorHandler, StatusCodeRedirect
 
from pylons.wsgiapp import PylonsApp
 
from routes.middleware import RoutesMiddleware
 
from pylons_app.lib.simplehg import SimpleHg
 
from pylons_app.lib.middleware.simplehg import SimpleHg
 
from pylons_app.lib.middleware.https_fixup import HttpsFixup
 
from pylons_app.config.environment import load_environment
 

	
 
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
 
    """Create a Pylons WSGI application and return it
 

	
 
    ``global_conf``
 
@@ -39,12 +40,14 @@ def make_app(global_conf, full_stack=Tru
 
    
 
    # Routing/Session/Cache Middleware
 
    app = RoutesMiddleware(app, config['routes.map'])
 
    app = SessionMiddleware(app, config)
 
    
 
    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)    
 
    #set the https based on HTTP_X_URL_SCHEME
 
    app = HttpsFixup(app)
 
    app = SimpleHg(app, config)
 
    
 
    if asbool(full_stack):
 
        # Handle Python exceptions
 
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
 

	
pylons_app/lib/hgapp.py
Show inline comments
 
deleted file
pylons_app/lib/middleware/__init__.py
Show inline comments
 
new file 100644
pylons_app/lib/middleware/https_fixup.py
Show inline comments
 
new file 100644
 
class HttpsFixup(object):
 
    def __init__(self, app):
 
        self.application = app
 
    
 
    def __call__(self, environ, start_response):
 
        self.__fixup(environ)
 
        return self.application(environ, start_response)
 
    
 
    
 
    def __fixup(self, environ):
 
        """Function to fixup the environ as needed. In order to use this
 
        middleware you should set this header inside your 
 
        proxy ie. nginx, apache etc.
 
        """
 
        proto = environ.get('HTTP_X_URL_SCHEME')
 
            
 
        if proto == 'https':
 
            environ['wsgi.url_scheme'] = proto
 
        else:
 
            environ['wsgi.url_scheme'] = 'http'
 
        return None
pylons_app/lib/middleware/simplehg.py
Show inline comments
 
file renamed from pylons_app/lib/simplehg.py to pylons_app/lib/middleware/simplehg.py
 
@@ -31,14 +31,12 @@ class SimpleHg(object):
 
        self.config = config
 
        #authenticate this mercurial request using 
 
        realm = '%s %s' % (config['hg_app_name'], 'mercurial repository')
 
        self.authenticate = AuthBasicAuthenticator(realm, authfunc)
 
        
 
    def __call__(self, environ, start_response):
 
        #dirty fix for https
 
        environ['wsgi.url_scheme'] = 'https'
 
        if not is_mercurial(environ):
 
            return self.application(environ, start_response)
 
        else:
 
            #===================================================================
 
            # AUTHENTICATE THIS MERCURIAL REQUEST
 
            #===================================================================
0 comments (0 inline, 0 general)