1 \section{\module{CGIHTTPServer
} ---
2 CGI-capable HTTP request handler
}
5 \declaremodule{standard
}{CGIHTTPServer
}
6 \sectionauthor{Moshe Zadka
}{moshez@zadka.site.co.il
}
7 \modulesynopsis{This module provides a request handler for HTTP servers
8 which can run CGI scripts.
}
11 The
\module{CGIHTTPServer
} module defines a request-handler class,
12 interface compatible with
13 \class{BaseHTTPServer.BaseHTTPRequestHandler
} and inherits behavior
14 from
\class{SimpleHTTPServer.SimpleHTTPRequestHandler
} but can also
17 \note{This module can run CGI scripts on
\UNIX{} and Windows systems;
18 on Mac OS it will only be able to run Python scripts within the same
21 The
\module{CGIHTTPServer
} module defines the following class:
23 \begin{classdesc
}{CGIHTTPRequestHandler
}{request, client_address, server
}
24 This class is used to serve either files or output of CGI scripts from
25 the current directory and below. Note that mapping HTTP hierarchic
26 structure to local directory structure is exactly as in
27 \class{SimpleHTTPServer.SimpleHTTPRequestHandler
}.
29 The class will however, run the CGI script, instead of serving it as a
30 file, if it guesses it to be a CGI script. Only directory-based CGI
31 are used --- the other common server configuration is to treat special
32 extensions as denoting CGI scripts.
34 The
\function{do_GET()
} and
\function{do_HEAD()
} functions are
35 modified to run CGI scripts and serve the output, instead of serving
36 files, if the request leads to somewhere below the
37 \code{cgi_directories
} path.
40 The
\class{CGIHTTPRequestHandler
} defines the following data member:
42 \begin{memberdesc
}{cgi_directories
}
43 This defaults to
\code{['/cgi-bin', '/htbin'
]} and describes
44 directories to treat as containing CGI scripts.
47 The
\class{CGIHTTPRequestHandler
} defines the following methods:
49 \begin{methoddesc
}{do_POST
}{}
50 This method serves the
\code{'POST'
} request type, only allowed for
51 CGI scripts. Error
501, "Can only POST to CGI scripts", is output
52 when trying to POST to a non-CGI url.
55 Note that CGI scripts will be run with UID of user nobody, for security
56 reasons. Problems with the CGI script will be translated to error
403.
58 For example usage, see the implementation of the
\function{test()
}
63 \seemodule{BaseHTTPServer
}{Base class implementation for Web server