[CherryPy] #644: WSGI SCRIPT_NAME and PATH_INFO

0 views
Skip to first unread message

CherryPy

unread,
Jan 14, 2007, 1:10:50 PM1/14/07
to cherrypy...@googlegroups.com
#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

CherryPy

unread,
Jan 14, 2007, 6:23:24 PM1/14/07
to cherrypy...@googlegroups.com
#644: WSGI SCRIPT_NAME and PATH_INFO
---------------------------+------------------------------------------------
Reporter: lawouach | Owner: rdelon
Type: defect | Status: new
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: wsgi |
---------------------------+------------------------------------------------
Old description:
New description:
Comment (by fumanchu):

PEP 333 is hard to understand because it follows CGI, which also allows
SCRIPT_NAME and PATH_INFO to be "". Selector is therefore making an
unwarranted assumption, and should normalize "" to "/" if it so desires.

CherryPy

unread,
Jan 14, 2007, 11:05:44 PM1/14/07
to cherrypy...@googlegroups.com
#644: WSGI SCRIPT_NAME and PATH_INFO
---------------------------+------------------------------------------------
Reporter: lawouach | Owner: rdelon
Type: defect | Status: new
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: wsgi |
---------------------------+------------------------------------------------
Comment (by dowski):

Lawouach: can't you simply solve your problem by doing:

{{{
wsgi_apps = [('', s)]
}}}

or

{{{
server = wsgiserver.CherryPyWSGIServer(('localhost', 8070), s,
server_name='localhost')
}}}

??

I'm not clear on where "CP sets {{{PATH_INFO}}} to {{{''}}} and
{{{SCRIPT_NAME}}} to {{{'/'}}}." I didn't see that in
{{{wsgiserver.__init__.py}}}.

--
Ticket URL: <http://cherrypy.org/ticket/644>

CherryPy

unread,
Jan 15, 2007, 2:27:55 AM1/15/07
to cherrypy...@googlegroups.com
#644: WSGI SCRIPT_NAME and PATH_INFO
---------------------------+------------------------------------------------
Reporter: lawouach | Owner: rdelon
Type: defect | Status: new
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: wsgi |
---------------------------+------------------------------------------------
Comment (by lawouach):

Robert: this is precisely my point :) Maybe I should report this question
to WEB-SIG.

Christian: I will try but this doesn't really answer the long term
problem. It's more like a workaround.

CherryPy

unread,
Jan 15, 2007, 3:52:48 AM1/15/07
to cherrypy...@googlegroups.com
#644: WSGI SCRIPT_NAME and PATH_INFO
---------------------------+------------------------------------------------
Reporter: lawouach | Owner: rdelon
Type: defect | Status: new
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: wsgi |
---------------------------+------------------------------------------------
Comment (by lawouach):

Christian, your trick seems to have fixed my problem. Shall we document it
as "the proper way to do?"

CherryPy

unread,
Jan 15, 2007, 12:37:06 PM1/15/07
to cherrypy...@googlegroups.com
#644: WSGI SCRIPT_NAME and PATH_INFO
---------------------------+------------------------------------------------
Reporter: lawouach | Owner: rdelon
Type: defect | Status: new
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution:
Keywords: wsgi |
---------------------------+------------------------------------------------
Comment (by dowski):

Well, I think it the the typical "WSGI way" of handling it. It is
confusing though. An app with a {{{SCRIPT_NAME}}} of {{{""}}} and
{{{PATH_INFO}}} of {{{"/"}}} doesn't make much more sense to me than an
with a {{{SCRIPT_NAME}}} of {{{"/"}}} and {{{PATH_INFO}}} of {{{""}}}.

C'est la vie ;-)

CherryPy

unread,
Jun 17, 2007, 4:28:49 PM6/17/07
to cherrypy...@googlegroups.com
#644: WSGI SCRIPT_NAME and PATH_INFO
---------------------------+------------------------------------------------
Reporter: lawouach | Owner: rdelon
Type: defect | Status: closed
Priority: normal | Milestone: 3.1
Component: CherryPy code | Resolution: fixed
Keywords: wsgi |
---------------------------+------------------------------------------------
Changes (by fumanchu):

* resolution: => fixed
* status: new => closed

Comment:

CherryPy 3 requires Application.script_name (and Request.script_name) to
never end with a slash. So CP should never "set SCRIPT_NAME to /". This
has been fixed in [1671].
Reply all
Reply to author
Forward
0 new messages