Fred Drake | 21572fd | 1999-06-14 19:47:47 +0000 | [diff] [blame] | 1 | \section{\module{CGIHTTPServer} --- |
Fred Drake | 4d3714b | 2000-10-10 16:56:41 +0000 | [diff] [blame] | 2 | CGI-capable HTTP request handler} |
Fred Drake | 21572fd | 1999-06-14 19:47:47 +0000 | [diff] [blame] | 3 | |
| 4 | |
| 5 | \declaremodule{standard}{CGIHTTPServer} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 6 | \platform{Unix} |
Fred Drake | 57657bc | 2000-12-01 15:25:23 +0000 | [diff] [blame] | 7 | \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il} |
Fred Drake | 21572fd | 1999-06-14 19:47:47 +0000 | [diff] [blame] | 8 | \modulesynopsis{This module provides a request handler for HTTP servers |
| 9 | which can run CGI scripts.} |
| 10 | |
| 11 | |
| 12 | The \module{CGIHTTPServer} module defines a request-handler class, |
| 13 | interface compatible with |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 14 | \class{BaseHTTPServer.BaseHTTPRequestHandler} and inherits behavior |
Fred Drake | 21572fd | 1999-06-14 19:47:47 +0000 | [diff] [blame] | 15 | from \class{SimpleHTTPServer.SimpleHTTPRequestHandler} but can also |
| 16 | run CGI scripts. |
| 17 | |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 18 | \strong{Note:} This module is \UNIX{} dependent since it creates the |
| 19 | CGI process using \function{os.fork()} and \function{os.exec()}. |
| 20 | |
Fred Drake | 21572fd | 1999-06-14 19:47:47 +0000 | [diff] [blame] | 21 | The \module{CGIHTTPServer} module defines the following class: |
| 22 | |
| 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}. |
| 28 | |
| 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. |
| 33 | |
| 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. |
| 38 | \end{classdesc} |
| 39 | |
| 40 | The \class{CGIHTTPRequestHandler} defines the following data member: |
| 41 | |
| 42 | \begin{memberdesc}{cgi_directories} |
| 43 | This defaults to \code{['/cgi-bin', '/htbin']} and describes |
| 44 | directories to treat as containing CGI scripts. |
| 45 | \end{memberdesc} |
| 46 | |
| 47 | The \class{CGIHTTPRequestHandler} defines the following methods: |
| 48 | |
| 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. |
| 53 | \end{methoddesc} |
| 54 | |
| 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. |
| 57 | |
| 58 | For example usage, see the implementation of the \function{test()} |
| 59 | function. |
| 60 | |
| 61 | |
| 62 | \begin{seealso} |
| 63 | \seemodule{BaseHTTPServer}{Base class implementation for Web server |
| 64 | and request handler.} |
| 65 | \end{seealso} |