blob: 6de2106da46117434f8e7a024ed410801aeb7452 [file] [log] [blame]
Fred Drake21572fd1999-06-14 19:47:47 +00001\section{\module{SimpleHTTPServer} ---
2 A Do-Something Request Handler}
3
4\declaremodule{standard}{SimpleHTTPServer}
5\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
6\modulesynopsis{This module provides a request handler for HTTP servers.}
7
8
9The \module{SimpleHTTPServer} module defines a request-handler class,
10interface compatible with \class{BaseHTTPServer.BaseHTTPRequestHandler}
11which serves files only from a base directory.
12
13The \module{SimpleHTTPServer} module defines the following class:
14
15\begin{classdesc}{SimpleHTTPRequestHandler}{request, client_address, server}
16This class is used, to serve files from current directory and below,
17directly mapping the directory structure to HTTP requests.
18
19A lot of the work is done by the base class
20\class{BaseHTTPServer.BaseHTTPRequestHandler}, such as parsing the
21request. This class implements the \function{do_GET()} and
22\function{do_HEAD()} functions.
23\end{classdesc}
24
25The \class{SimpleHTTPRequestHandler} defines the following member
26variables:
27
28\begin{memberdesc}{server_version}
29This will be \code{"SimpleHTTP/" + __version__}, where \code{__version__}
30is defined in the module.
31\end{memberdesc}
32
33\begin{memberdesc}{extensions_map}
34A dictionary mapping suffixes into MIME types. Default is signified
35by an empty string, and is considered to be \code{text/plain}.
36The mapping is used case-insensitively, and so should contain only
37lower-cased keys.
38\end{memberdesc}
39
40The \class{SimpleHTTPRequestHandler} defines the following methods:
41
42\begin{methoddesc}{do_HEAD}{}
43This method serves the \code{'HEAD'} request type: it sends the
44headers it would send for the equivalent \code{GET} request. See the
45\method{do_GET()} method for more complete explanation of the possible
46headers.
47\end{methoddesc}
48
49\begin{methoddesc}{do_GET}{}
50The request is mapped to a local file by interpreting the request as
51a path relative to the current working directory.
52
53If the request was mapped to a directory, a \code{403} respond is output,
54followed by the explanation \code{'Directory listing not supported'}.
55Any \exception{IOError} exception in opening the requested file, is mapped
56to a \code{404}, \code{'File not found'} error. Otherwise, the content
57type is guessed using the \var{extensions_map} variable.
58
59A \code{'Content-type:'} with the guessed content type is output, and
60then a blank line, signifying end of headers, and then the contents of
61the file. The file is always opened in binary mode.
62
63For example usage, see the implementation of the \function{test()}
64function.
65\end{methoddesc}
66
67
68\begin{seealso}
69 \seemodule{BaseHTTPServer}{Base class implementation for Web server
70 and request handler.}
71\end{seealso}