[Web-SIG] Who is responsible for SCRIPT_NAME?

Phillip J. Eby pje at telecommunity.com
Tue Feb 7 12:50:37 CET 2006

At 11:12 PM 2/6/2006 -0800, Robert Brewer wrote:
>Ian Bicking said:
> > The HTTP server should always set SCRIPT_NAME to ''.
>Christian asked:
> > If it is a full blown WSGI compliant HTTP server,
> > why should it do that? Shouldn't it support mounting
> > applications at various points (SCRIPT_NAME locations)?
>and Ian replied:
> > It doesn't really need to do that, it's easy to do
> > that in the WSGI application itself.  For instance:
> >
> > def dispatch(app_map):
> >     ...
> >
> > I can understand this is a common desire and it
> > is not obvious that you can do this, so it might
> > be useful to include some middleware like this.
> > But the server itself does not need to do this.
> > And there's lots of ways you might want to do
> > this (e.g., virtual hosts, which do the same
> > basic thing but match against environ['HTTP_HOST']).
> > Paste includes code along these lines in paste.urlmap
>Aargh. This is getting really confusing for me as the author of WSGI 
>gateways (wrappers around non-WSGI HTTP servers, like mod_python + 
>Apache), one of the maintainers of a pure WSGI HTTP server (in CherryPy) 
>and the primary developer of a WSGI interface for a popular app framework 
>(CherryPy). On the one hand, I'm being told that WSGI apps need to "obey" 
>SCRIPT_NAME no matter where it comes from, and on the other, I'm being 
>told that SCRIPT_NAME is essentially ignorable. I'm getting tired of the 
>Dear Web-SIG, please weigh in. Who is responsible for SCRIPT_NAME (setting 
>and/or interpreting it) and what does it "mean"? I've been told that PEP 
>333 requires that the origin server (like my modpython_gateway, for 
>example) must be told the "mount point" of every WSGI app it serves and 
>set SCRIPT_NAME to that, always, so the app can trust it. Now (by the same 
>person, as far as I can tell) I'm being told that the origin server should 
>always set SCRIPT_NAME to "", which IMO denies the reason for its 
>inclusion in the spec.

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.

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

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.

More information about the Web-SIG mailing list