The SimpleHTTPServer module defines a request-handler class, interface-compatible with BaseHTTPServer.BaseHTTPRequestHandler, that serves files only from a base directory.
The SimpleHTTPServer module defines the following class:
request, client_address, server) |
A lot of the work, such as parsing the request, is done by the base class BaseHTTPServer.BaseHTTPRequestHandler. This class implements the do_GET() and do_HEAD() functions.
The SimpleHTTPRequestHandler defines the following member variables:
"SimpleHTTP/" + __version__
, where __version__
is defined in the module.
application/octet-stream
.
The mapping is used case-insensitively, and so should contain only
lower-cased keys.
The SimpleHTTPRequestHandler defines the following methods:
) |
'HEAD'
request type: it sends the
headers it would send for the equivalent GET
request. See the
do_GET() method for a more complete explanation of the possible
headers.
) |
If the request was mapped to a directory, the directory is checked for
a file named index.html
or index.htm
(in that order).
If found, the file's contents are returned; otherwise a directory
listing is generated by calling the list_directory() method.
This method uses os.listdir() to scan the directory, and
returns a 404
error response if the listdir() fails.
If the request was mapped to a file, it is opened and the contents are
returned. Any IOError exception in opening the requested
file is mapped to a 404
, 'File not found'
error. Otherwise, the content type is guessed by calling the
guess_type() method, which in turn uses the
extensions_map variable.
A 'Content-type:'
header with the guessed content type is
output, followed by a blank line signifying the end of the headers,
and then the contents of the file are output. If the file's MIME type
starts with text/
the file is opened in text mode; otherwise
binary mode is used.
For example usage, see the implementation of the test() function.
See Also: