at some point I said:
>> SCRIPT_NAME = '/apps/cherrypy' #the path to the CP wsgiApp
>> PATH_INFO = '/projectapp/tags/filters'
and Robert countered:
>> The problem here is that you should expect:
>> SCRIPT_NAME = '/apps/cherrypy/projectapp'
>> PATH_INFO = '/tags/filters'
then I answered:
>> ...the way I understood it, SCRIPT_NAME is the path up to the
>> wsgiApp callable. '/projectapp/tags/filters' is a path to a
>> "sub-app" hosted within the CP wsgiApp that is dispatched by CP.
then Phillip J. Eby wrote on web-
...@python.org (in a different discussion):
>> My suggestion would be to add an extra WSGI key,
>> maybe 'wsgi.application_root' to represent the
>> "original application SCRIPT_NAME" for frameworks
>> that have such a concept. Templates using Routes
>> could then use that variable in place of SCRIPT_NAME.
>> It seems to me that Zope request/response objects
>> also need this information, in order to generate
>> the magic URL0-URL9 and other such variables.
>> The application root should of course be set at the entry point
>> of the framework, so in the case of Routes, Routes could simply
>> copy SCRIPT_NAME to application_root in environ if there isn't
>> one already set. It could then simply use application_root
>> first when generating URLs, and for that matter it could add
>> extension APIs to the environ to allow accessing Routes
>> APIs from embedded apps.
>> ...this allows entire mini-applications with their own URL
>> space to be embedded as "templates" within a containing
>> application. Such apps can then rely on SCRIPT_NAME as
>> being their root, even if they weren't originally written
>> for embedding.
which Robert followed with:
> IMO, Phillip's comments add support for my interpretation of SCRIPT_NAME
> (as it relates to CherryPy): that it's perfectly OK for SCRIPT_NAME to
> be something other than "the path up to the wsgiApp callable". When I
> wrote wsgiApp, it was designed to be completely independent of the URL:
> one callable for multiple "WSGI apps"; each "CP app", when invoked via
> _cpwsgi, equates to one "WSGI app". I can see now that I should not have
> called it "wsgiApp". :(
I've been following that web-sig discussion as well, and maybe I'm wrong
here, but I think he is referring to changing SCRIPT_NAME within a
wsgiApp for the benefit of a hosted wsgiApp. And that is totally cool.
Once we are inside of the CP dispatch process, if it can determine
that "projectapp" is the target CP-app in question and rewrite
SCRIPT_NAME from "/apps/cherrypy" to "/apps/cherrypy/projectapp" and
PATH_INFO to "/tags/filters", that is fine with me.
I actually do that in my WSGIAppFilter - I use
_cputil.get_object_trail() to determine what portion of PATH_INFO
corresponds to objects mounted on the tree. So SCRIPT_NAME becomes
SCRIPT_NAME + cp_tree_object_parts. The remainder of the path that
doesn't correspond to objects in the CP tree is set to PATH_INFO. Thus,
the hosted wsgi app gets a SCRIPT_NAME and PATH_INFO that are correct in
its context.
> PEP 333 takes pains to say "the application object" or "the application
> callable" in many, many places where it could have just said "the
> application"--I think there's a reason, and it is that "the callable" is
> supposed to be decoupled from "the application". One common way to
> implement that for a framework is to make "the callable" a factory
> function which returns "the real callable"; I chose in CP to use
> polymorphism ("many apps -> one function") rather than use a factory
> ("many apps -> one function -> many functions").
I like the polymorphism approach. I just think that the
_cpwsgi.wsgiApp, as a single "application callable", should dispatch to
its multiple hosted wsgi apps with PATH_INFO (i.e., that should be the
object_path). From within, if it wants to rewrite SCRIPT_NAME and
PATH_INFO to reflect the true location of the internal app, that is
fine. It really is the only way that a correct SCRIPT_NAME and
PATH_INFO could be set since only CP knows the internal object structure
of the tree.
So here is what I am proposing, in a nutshell:
1. Have CP ignore SCRIPT_NAME for locating the object requested.
2. Use PATH_INFO to locate the requested object.
3. Optionally: rewrite SCRIPT_NAME to be the original SCRIPT_NAME + the
"found application" (however that is determined - I gave my
WSGIAppFilter example).
4. Use SCRIPT_NAME + path when writing issuing redirects and other URL
writing tasks.
> /soapbox off ;)
Me too :-)
Christian