@@ -39,7 +39,17 @@ handler. Code to create and run the server looks like this::
3939 This class builds on the :class: `~socketserver.TCPServer ` class by storing
4040 the server address as instance variables named :attr: `server_name ` and
4141 :attr: `server_port `. The server is accessible by the handler, typically
42- through the handler's :attr: `server ` instance variable.
42+ through the handler's :attr: `~socketserver.BaseRequestHandler.server `
43+ instance variable.
44+
45+ .. attribute :: server_name
46+
47+ The HTTP server's fully qualified domain name.
48+
49+ .. attribute :: server_port
50+
51+ The HTTP server's port number obtained from *server_address *.
52+
4353
4454.. class :: ThreadingHTTPServer(server_address, RequestHandlerClass)
4555
@@ -350,6 +360,14 @@ provides three different variants:
350360 This will be ``"SimpleHTTP/" + __version__ ``, where ``__version__ `` is
351361 defined at the module level.
352362
363+ .. attribute :: index_pages
364+
365+ Specifies the filenames that are treated as directory index pages.
366+
367+ Defaults to ``("index.html", "index.htm") ``.
368+
369+ .. versionadded :: 3.12
370+
353371 .. attribute :: extensions_map
354372
355373 A dictionary mapping suffixes into MIME types, contains custom overrides
@@ -373,8 +391,8 @@ provides three different variants:
373391 The request is mapped to a local file by interpreting the request as a
374392 path relative to the current working directory.
375393
376- If the request was mapped to a directory, the directory is checked for a
377- file named `` index.html `` or `` index.htm `` (in that order) . If found, the
394+ If the request was mapped to a directory, the directory is checked for
395+ an index page as specified by :attr: ` index_pages ` . If found, the
378396 file's contents are returned; otherwise a directory listing is generated
379397 by calling the :meth: `list_directory ` method. This method uses
380398 :func: `os.listdir ` to scan the directory, and returns a ``404 `` error
@@ -401,6 +419,30 @@ provides three different variants:
401419 .. versionchanged :: 3.7
402420 Support of the ``'If-Modified-Since' `` header.
403421
422+ .. method :: list_directory(path)
423+
424+ Helper to list the contents of *path * when no index page is present.
425+
426+ This returns either a :term: `file-like object ` (which must be closed
427+ by the caller) or ``None `` to indicate an error, in which case the
428+ caller has nothing further to do. In either case, the headers are sent.
429+
430+ .. method :: guess_type(path)
431+
432+ Guess the type of the file at the given *path *.
433+
434+ This returns a string of the form ``type/subtype ``, usable for
435+ a MIME Content-type header.
436+
437+ The default implementation looks the file's extension up in
438+ :attr: `extensions_map `, falling back to
439+ :func: `mimetypes.guess_file_type ` and then to
440+ ``'application/octet-stream' ``.
441+
442+ .. versionchanged :: 3.13
443+ Add :func: `mimetypes.guess_file_type ` as a fallback.
444+
445+
404446The :class: `SimpleHTTPRequestHandler ` class can be used in the following
405447manner in order to create a very basic webserver serving files relative to
406448the current directory::
@@ -419,7 +461,7 @@ the current directory::
419461
420462:class: `SimpleHTTPRequestHandler ` can also be subclassed to enhance behavior,
421463such as using different index file names by overriding the class attribute
422- :attr: `index_pages `.
464+ :attr: `~SimpleHTTPRequestHandler. index_pages `.
423465
424466
425467.. class :: CGIHTTPRequestHandler(request, client_address, server)
@@ -440,7 +482,9 @@ such as using different index file names by overriding the class attribute
440482 the other common server configuration is to treat special extensions as
441483 denoting CGI scripts.
442484
443- The :func: `do_GET ` and :func: `do_HEAD ` functions are modified to run CGI scripts
485+ The :func: `~SimpleHTTPRequestHandler.do_GET ` and
486+ :func: `~SimpleHTTPRequestHandler.do_HEAD ` functions
487+ are modified to run CGI scripts
444488 and serve the output, instead of serving files, if the request leads to
445489 somewhere below the ``cgi_directories `` path.
446490
0 commit comments