Ticket #268 (new defect)
PrefixMiddleware shouldn't strip prefix from PATH_INFO
| Reported by: | catlee | Owned by: | ianb |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | deploy | Version: | svn-trunk |
| Severity: | normal | Keywords: | |
| Cc: | chris@… |
Description
I don't think that PrefixMiddleware? should be stripping the prefix from environPATH_INFO?.
I've run into this a few times when trying to deploy simple single-controller applications. One example is an application called 'signon' that manages single-signon for our intranet.
The app is deployed behind an apache reverse proxy which maps /signon on the apache server to the paste server. The signon application expects urls relative to its root to be actions like "signon", "signoff". So the client-visible url would be "/signon/signon".
PrefixMiddleware? currently strips the prefix from PATH_INFO, so "/signon/signon" gets passed to the application in PATH_INFO as "/" whereas "/signon/signoff" would get passed in as "/signoff". Other strange effects include "/signon/signon123" being passed in as "123"
I'm not sure if there is (or was) a use case for the current behaviour, in which case maybe an option to PrefixMiddleware? would be appropriate. Otherwise, the patch below should suffice.
-
tests/test_prefix_middleware.py
1 from paste.deploy.config import PrefixMiddleware 2 from paste.fixture import TestApp 3 from py.test import raises 4 5 class Bug(Exception): pass 6 7 def app(environ, start_response): 8 start_response('200 OK', [('Content-type', 'text/html')]) 9 retval = "%s %s" % (environ['PATH_INFO'], environ['SCRIPT_NAME']) 10 return iter(retval) 11 12 def test_prefix(): 13 wrapped = PrefixMiddleware(app, {'test': 1}, "/signon") 14 test_app = TestApp(wrapped) 15 assert "/ /signon" == test_app.get("/").normal_body 16 assert "/foo /signon" == test_app.get("/foo").normal_body 17 assert "/signoff /signon" == test_app.get("/signoff").normal_body 18 assert "/signon /signon" == test_app.get("/signon").normal_body -
paste/deploy/config.py
252 252 253 253 def __call__(self, environ, start_response): 254 254 url = environ['PATH_INFO'] 255 url = re.sub(self.regprefix, r'\1', url)256 255 if not url: url = '/' 257 256 environ['PATH_INFO'] = url 258 257 environ['SCRIPT_NAME'] = self.prefix
