blob: a2f453a6d8b9215ed0648cb6d559aabfe0efea0a [file] [log] [blame]
Fred Drake21572fd1999-06-14 19:47:47 +00001\section{\module{CGIHTTPServer} ---
2 A Do-Something Request Handler}
3
4
5\declaremodule{standard}{CGIHTTPServer}
Fred Drake38e5d272000-04-03 20:13:55 +00006 \platform{Unix}
Fred Drake21572fd1999-06-14 19:47:47 +00007\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
8\modulesynopsis{This module provides a request handler for HTTP servers
9 which can run CGI scripts.}
10
11
12The \module{CGIHTTPServer} module defines a request-handler class,
13interface compatible with
14\class{BaseHTTPServer.BaseHTTPRequestHandler} and inherits behaviour
15from \class{SimpleHTTPServer.SimpleHTTPRequestHandler} but can also
16run CGI scripts.
17
Fred Drake38e5d272000-04-03 20:13:55 +000018\strong{Note:} This module is \UNIX{} dependent since it creates the
19CGI process using \function{os.fork()} and \function{os.exec()}.
20
Fred Drake21572fd1999-06-14 19:47:47 +000021The \module{CGIHTTPServer} module defines the following class:
22
23\begin{classdesc}{CGIHTTPRequestHandler}{request, client_address, server}
24This class is used to serve either files or output of CGI scripts from
25the current directory and below. Note that mapping HTTP hierarchic
26structure to local directory structure is exactly as in
27\class{SimpleHTTPServer.SimpleHTTPRequestHandler}.
28
29The class will however, run the CGI script, instead of serving it as a
30file, if it guesses it to be a CGI script. Only directory-based CGI
31are used --- the other common server configuration is to treat special
32extensions as denoting CGI scripts.
33
34The \function{do_GET()} and \function{do_HEAD()} functions are
35modified to run CGI scripts and serve the output, instead of serving
36files, if the request leads to somewhere below the
37\code{cgi_directories} path.
38\end{classdesc}
39
40The \class{CGIHTTPRequestHandler} defines the following data member:
41
42\begin{memberdesc}{cgi_directories}
43This defaults to \code{['/cgi-bin', '/htbin']} and describes
44directories to treat as containing CGI scripts.
45\end{memberdesc}
46
47The \class{CGIHTTPRequestHandler} defines the following methods:
48
49\begin{methoddesc}{do_POST}{}
50This method serves the \code{'POST'} request type, only allowed for
51CGI scripts. Error 501, "Can only POST to CGI scripts", is output
52when trying to POST to a non-CGI url.
53\end{methoddesc}
54
55Note that CGI scripts will be run with UID of user nobody, for security
56reasons. Problems with the CGI script will be translated to error 403.
57
58For example usage, see the implementation of the \function{test()}
59function.
60
61
62\begin{seealso}
63 \seemodule{BaseHTTPServer}{Base class implementation for Web server
64 and request handler.}
65\end{seealso}