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