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