CGI server by Python
Alex Martelli
aleax at aleax.it
Sun Oct 6 03:25:19 EDT 2002
On Sunday 06 October 2002 02:27 am, Brian Lee wrote:
...
> CGIHTTPServer.py in Python does not support to run CGI not only
> in /cgi-bin/ but also other(more deeper) directory. I modified the
> code to run CGI in other directory(ex: /cgi-bin/a/b/c/test.cgi). But
Right, we went over that last time.
> I don't know how to set $PATH_INFO variable in my modified
> CGIHTTPServer.py
>
> Whe client request follow...
>
> http://www.senux.com/cgi-bin/a/b/c/test.cgi/test/argument/
>
> $SCRIPT_NAME should be /cgi-bin/a/b/c/test.cgi and $PATH_INFO sholud
> be /test/argument/ Then, how do you detect that test.cgi
> is a existing CGI file and the else string(/test/argument/)
> is value for $PATH_INFO ? (This is what I want to ask.)
It seems to me that the most general way is for the server to
test, in turn, the path's components, untii it finds one that is
not a directory. Now if that's a file, execute it, with PATH_INFO
set to all the rest; if it's neither a file nor a directory, you have
an error.
> I thought server can detect the point of CGI script file in client's
> request when the server check each file and directory in request. But
Right, that seems to be the most general way.
> it is pretty overloaded, I think.
>
> Something wrong in my knowlegage? Any advice?
If you're worried about performance, have your server study the
tree of subdirectories under cgi-bin at start-up, building a dict
to indicate what subdirectories do exist. Then, the testing at
runtime becomes quite a modest load. If you do this in the
simplest way, the server won't be able to properly identify any
new directory created while the server is running; but in fact
it's not too hard for the server to pick up such information on
the fly -- when the server's existing dict indicates a directory
doesn't exist, have the server do a last-ditch check just in case
the direcotry was actually created during the server's runtime,
and, if so, adjust the cache accordingly.
Alex
More information about the Python-list
mailing list