#644: WSGI SCRIPT_NAME and PATH_INFO
---------------------------+------------------------------------------------
Reporter: lawouach | Owner: rdelon
Type: defect | Status: new
Priority: normal | Milestone: 3.1
Component: CherryPy code | Keywords: wsgi
---------------------------+------------------------------------------------
Compare the following:
{{{
#!python
from cherrypy import wsgiserver
import selector
def my_crazy_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
return ['Hello world!\n']
s = selector.Selector()
s.add('/', GET=my_crazy_app)
# Here we set our application to the script_name '/'
wsgi_apps = [('/', s)]
server = wsgiserver.CherryPyWSGIServer(('localhost', 8070), wsgi_apps,
server_name='localhost')
if __name__ == '__main__':
server.start()
}}}
... with the code found at the top of wsgiserver/__init__.py
The only difference is the use of the selector package/
A request to
http://localhost:8070/ will return a 404 when without using
selector it would return the expected content.
The problem seems to lie on the fact that CP sets PATH_INFO to '' and
SCRIPT_NAME to '/'. But selector expects PATH_INFO to be set to '/' in
that case:
https://lukearno.com/svn-selector/trunk/selector.py
See the __call__ attribute.
Unfortunately I find PEP 333 very misleading on this specific occasion:
SCRIPT_NAME
The initial portion of the request URL's "path" that corresponds to
the application object, so that the application knows its virtual
"location". This may be an empty string, if the application corresponds to
the "root" of the server.
PATH_INFO
The remainder of the request URL's "path", designating the virtual
"location" of the request's target within the application. This may be an
empty string, if the request URL targets the application root and does not
have a trailing slash.
Seriously this doesn't help. It appears that wsgiref doesn't even bother
with SCRIPT_NAME and leaves it to '' all the time which is why selector
works with it.
So who is right? Who is wrong?
--
Ticket URL: <
http://www.cherrypy.org/ticket/644>
CherryPy <
http://www.cherrypy.org>
CherryPy - a pythonic, object-oriented HTTP framework