blob: df0728e3f182a5172de338eee713d965cfa8a1f8 [file] [log] [blame]
Fred Drake21572fd1999-06-14 19:47:47 +00001\section{\module{CGIHTTPServer} ---
Fred Drake4d3714b2000-10-10 16:56:41 +00002 CGI-capable HTTP request handler}
Fred Drake21572fd1999-06-14 19:47:47 +00003
4
5\declaremodule{standard}{CGIHTTPServer}
Fred Drake57657bc2000-12-01 15:25:23 +00006\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Fred Drake21572fd1999-06-14 19:47:47 +00007\modulesynopsis{This module provides a request handler for HTTP servers
8 which can run CGI scripts.}
9
10
11The \module{CGIHTTPServer} module defines a request-handler class,
12interface compatible with
Thomas Woutersf8316632000-07-16 19:01:10 +000013\class{BaseHTTPServer.BaseHTTPRequestHandler} and inherits behavior
Fred Drake21572fd1999-06-14 19:47:47 +000014from \class{SimpleHTTPServer.SimpleHTTPRequestHandler} but can also
15run CGI scripts.
16
Fred Drakee70dbe02001-11-19 05:16:35 +000017\note{This module can run CGI scripts on \UNIX{} and Windows systems;
18on Mac OS it will only be able to run Python scripts within the same
19process as itself.}
Fred Drake38e5d272000-04-03 20:13:55 +000020
Jeremy Hylton6414cd82004-12-22 14:19:09 +000021\note{CGI scripts run by the \class{CGIHTTPRequestHandler} class cannot execute
22redirects (HTTP code 302), because code 200 (script output follows)
23is sent prior to execution of the CGI script. This pre-empts the status
24code.}
25
Fred Drake21572fd1999-06-14 19:47:47 +000026The \module{CGIHTTPServer} module defines the following class:
27
28\begin{classdesc}{CGIHTTPRequestHandler}{request, client_address, server}
29This class is used to serve either files or output of CGI scripts from
30the current directory and below. Note that mapping HTTP hierarchic
31structure to local directory structure is exactly as in
32\class{SimpleHTTPServer.SimpleHTTPRequestHandler}.
33
34The class will however, run the CGI script, instead of serving it as a
35file, if it guesses it to be a CGI script. Only directory-based CGI
36are used --- the other common server configuration is to treat special
37extensions as denoting CGI scripts.
38
39The \function{do_GET()} and \function{do_HEAD()} functions are
40modified to run CGI scripts and serve the output, instead of serving
41files, if the request leads to somewhere below the
42\code{cgi_directories} path.
43\end{classdesc}
44
45The \class{CGIHTTPRequestHandler} defines the following data member:
46
47\begin{memberdesc}{cgi_directories}
48This defaults to \code{['/cgi-bin', '/htbin']} and describes
49directories to treat as containing CGI scripts.
50\end{memberdesc}
51
52The \class{CGIHTTPRequestHandler} defines the following methods:
53
54\begin{methoddesc}{do_POST}{}
55This method serves the \code{'POST'} request type, only allowed for
56CGI scripts. Error 501, "Can only POST to CGI scripts", is output
57when trying to POST to a non-CGI url.
58\end{methoddesc}
59
60Note that CGI scripts will be run with UID of user nobody, for security
61reasons. Problems with the CGI script will be translated to error 403.
62
63For example usage, see the implementation of the \function{test()}
64function.
65
66
67\begin{seealso}
68 \seemodule{BaseHTTPServer}{Base class implementation for Web server
69 and request handler.}
70\end{seealso}