[Web-SIG] Who is responsible for SCRIPT_NAME?

Robert Brewer fumanchu at amor.org
Tue Feb 7 21:18:38 CET 2006

Phillip J. Eby wrote:
> The only time you should set SCRIPT_NAME to "" is if the 
> application object being executed is mounted at the server
> root.  So, this is correct behavior for a server like
> wsgiref's SimpleHTTPServer, which does not provide any
> mount points.  If your server implements mount points, you 
> should indeed set SCRIPT_NAME to appropriate path for
> the app being executed.

Thanks; that makes sense, and is how I've always interpreted the spec.

> As far as I can tell, the only confusion in the conversation 
> was that Ian was trying to point out that middleware can be
> used to implement mount points, rather than building mount
> points directly into the server.  That is, he was making an
> implementation suggestion that a server (especially one
> destined for stdlib inclusion) can be simpler if it just
> provides a single mount point at the root and leaves the
> routing to a middleware component -- which of course would
> then be reusable and interchangeable.  And if that wasn't
> what he meant by saying the server should set SCRIPT_NAME
> to "", then he's wrong.  ;)

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 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.

1. If "the application" refers to the end app or framework, then I think
many people (me included) are expecting that whatever SCRIPT_NAME is set
by the origin server should pass through unchanged to the end app. If
true, then it seems to me we're saying that this part of the spec simply
doesn't apply to the origin-server-to-routing-middleware part of the
conversation, because the origin server doesn't know whether the
application corresponds to the "root" of the server or not (only the
middleware knows). So the first half of the WSGI conversation
(server-to-middleware) doesn't strictly follow the spec.

I don't mind that, but the spec could be clearer by saying SHOULD or
MUST in the above block, and (if it's SHOULD instead of MUST) detailing
the "middleware routing scenario", in which the origin server isn't
responsible to set SCRIPT_NAME to the end application's virtual location
if middleware is going to do that instead.

2. "The application" could refer to the routing-middleware (because it
implements both the application side and the server side of the spec).
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).

So which one is the correct interpretation, 1 or 2?

Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org

More information about the Web-SIG mailing list