[Web-SIG] Who is responsible for SCRIPT_NAME?
Phillip J. Eby
pje at telecommunity.com
Tue Feb 7 21:35:38 CET 2006
At 12:18 PM 2/7/2006 -0800, Robert Brewer wrote:
>Here's my continuing issue: if we allow middleware to implement mount
>points, then your first statement (above) needs to be modified to:
> The only time [the origin server] should set SCRIPT_NAME
> to "" is if the application object being executed is
> mounted at the server root OR you use a dumb server
> and instead rely on middleware to do the routing.
I don't follow you here. My original statement was precisely correct;
SCRIPT_NAME should be set to "" if and only if the application to be
invoked is mounted at the origin server's root. That is, if the URL path
that addresses the application is '/'.
This statement applies to middleware as well as to the origin server, as
the middleware is obliged to set SCRIPT_NAME correctly for any application
that *it* calls. Nor is this a distinction without a difference; it's
possible for a middleware component to exist only to filter or handle
certain conditions, but be a passthrough for others, in which case it might
leave an empty SCRIPT_NAME alone.
> > I don't think the *spec* is ambiguous on this, but if you can
> > point out a bit that makes it seem uncertain, please feel
> > free to suggest additional or alternate wording. Thanks.
> 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.
>This section is becoming increasingly ambiguous to me. If you're using
>middleware to do the routing, I don't know whether "the application"
>refers to the middleware or to the end app which the middleware wraps.
"The application" always refers to the application that is *receiving* the
>1. If "the application" refers to the end app or framework
>2. "The application" could refer to the routing-middleware (because it
"Application" simply refers to any code that is reading an 'environ' that
it received from *its* server. So *both* of these are "applications", and
each should see the correct value of SCRIPT_NAME.
The simple explanation is that SCRIPT_NAME must always reflect the path
that was followed to get to the *current* application.
>In other words, to the origin server, the routing-middleware's callable
>is the only WSGI application to care about, and it's always "mounted at
>root" so SCRIPT_NAME can always be "".
> I haven't adopted this
>interpretation, because in my mind, middleware isn't mounted
>anywhere--it's a filter for the end app(s).
As far as any server knows, a given piece of middleware *is* an
application. Ergo, it has a location at which it must be considered
"mounted" in the server.
There is really very little that's special about middleware; it's simply an
app that's also a server. There are some additional rules to make sure
that middleware composition behaves sanely, but apart from those extra
rules, middleware has all of the freedoms (and restrictions) of both a
server and an application.
More information about the Web-SIG