@@ -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
@@ -60,7 +70,7 @@ handler. Code to create and run the server looks like this::
6070 object fails with a :exc: `RuntimeError `.
6171
6272 The *certfile * argument is the path to the SSL certificate chain file,
63- and the *keyfile * is the path to file containing the private key.
73+ and the *keyfile * is the path to the file containing the private key.
6474
6575 A *password * can be specified for files protected and wrapped with PKCS#8,
6676 but beware that this could possibly expose hardcoded passwords in clear.
@@ -140,7 +150,7 @@ instantiation, of which this module provides three different variants:
140150
141151 .. attribute :: path
142152
143- Contains the request path. If query component of the URL is present,
153+ Contains the request path. If the query component of the URL is present,
144154 then ``path `` includes the query. Using the terminology of :rfc: `3986 `,
145155 ``path `` here includes ``hier-part `` and the ``query ``.
146156
@@ -190,7 +200,7 @@ instantiation, of which this module provides three different variants:
190200 Specifies a format string that should be used by :meth: `send_error ` method
191201 for building an error response to the client. The string is filled by
192202 default with variables from :attr: `responses ` based on the status code
193- that passed to :meth: `send_error `.
203+ passed to :meth: `send_error `.
194204
195205 .. attribute :: error_content_type
196206
@@ -238,8 +248,8 @@ instantiation, of which this module provides three different variants:
238248 .. method :: handle_expect_100()
239249
240250 When an HTTP/1.1 conformant server receives an ``Expect: 100-continue ``
241- request header it responds back with a ``100 Continue `` followed by ``200
242- OK `` headers.
251+ request header it responds with a ``100 Continue `` followed by ``200 OK ``
252+ headers.
243253 This method can be overridden to raise an error if the server does not
244254 want the client to continue. For example, the server can choose to send ``417
245255 Expectation Failed `` as a response header and ``return False ``.
@@ -295,8 +305,8 @@ instantiation, of which this module provides three different variants:
295305 .. method :: send_response_only(code, message=None)
296306
297307 Sends the response header only, used for the purposes when ``100
298- Continue `` response is sent by the server to the client. The headers not
299- buffered and sent directly the output stream.If the *message * is not
308+ Continue `` response is sent by the server to the client. The headers are
309+ not buffered and sent directly the output stream. If the *message * is not
300310 specified, the HTTP message corresponding the response *code * is sent.
301311
302312 This method does not reject *message * containing CRLF sequences.
@@ -338,7 +348,7 @@ instantiation, of which this module provides three different variants:
338348 to create custom error logging mechanisms. The *format * argument is a
339349 standard printf-style format string, where the additional arguments to
340350 :meth: `log_message ` are applied as inputs to the formatting. The client
341- ip address and current date and time are prefixed to every message logged.
351+ IP address and current date and time are prefixed to every message logged.
342352
343353 .. method :: version_string()
344354
@@ -402,6 +412,14 @@ instantiation, of which this module provides three different variants:
402412
403413 .. versionadded :: 3.15
404414
415+ .. attribute :: index_pages
416+
417+ Specifies the filenames that are treated as directory index pages.
418+
419+ Defaults to ``("index.html", "index.htm") ``.
420+
421+ .. versionadded :: 3.12
422+
405423 .. attribute :: extensions_map
406424
407425 A dictionary mapping suffixes into MIME types, contains custom overrides
@@ -434,8 +452,8 @@ instantiation, of which this module provides three different variants:
434452 The request is mapped to a local file by interpreting the request as a
435453 path relative to the current working directory.
436454
437- If the request was mapped to a directory, the directory is checked for a
438- file named `` index.html `` or `` index.htm `` (in that order) . If found, the
455+ If the request was mapped to a directory, the directory is checked for
456+ an index page as specified by :attr: ` index_pages ` . If found, the
439457 file's contents are returned; otherwise a directory listing is generated
440458 by calling the :meth: `list_directory ` method. This method uses
441459 :func: `os.listdir ` to scan the directory, and returns a ``404 `` error
@@ -465,9 +483,32 @@ instantiation, of which this module provides three different variants:
465483 .. versionchanged :: 3.7
466484 Support of the ``'If-Modified-Since' `` header.
467485
468- The :class: `SimpleHTTPRequestHandler ` class can be used in the following
469- manner in order to create a very basic webserver serving files relative to
470- the current directory::
486+ .. method :: list_directory(path)
487+
488+ Helper to list the contents of *path * when no index page is present.
489+
490+ This returns either a :term: `file-like object ` (which must be closed
491+ by the caller) or ``None `` to indicate an error, in which case the
492+ caller has nothing further to do. In either case, the headers are sent.
493+
494+ .. method :: guess_type(path)
495+
496+ Guess the type of the file at the given *path *.
497+
498+ This returns a string of the form ``type/subtype ``, usable for
499+ a MIME Content-type header.
500+
501+ The default implementation looks the file's extension up in
502+ :attr: `extensions_map `, falling back to
503+ :func: `mimetypes.guess_file_type ` and then to
504+ :attr: `default_content_type `.
505+
506+ .. versionchanged :: 3.13
507+ Add :func: `mimetypes.guess_file_type ` as a fallback.
508+
509+
510+ The :class: `SimpleHTTPRequestHandler ` class can be used to create a very basic
511+ webserver serving files relative to the current directory as follows::
471512
472513 import http.server
473514 import socketserver
@@ -483,7 +524,7 @@ the current directory::
483524
484525:class: `SimpleHTTPRequestHandler ` can also be subclassed to enhance behavior,
485526such as using different index file names by overriding the class attribute
486- :attr: `index_pages `.
527+ :attr: `~SimpleHTTPRequestHandler. index_pages `.
487528
488529
489530.. _http-server-cli :
@@ -599,8 +640,8 @@ The following options are accepted:
599640
600641.. option :: -H , --header <header > <value >
601642
602- Specify an additional extra HTTP Response Header to send on successful HTTP
603- 200 responses. Can be used multiple times to send additional custom response
643+ Specify an additional HTTP Response Header to send on successful HTTP 200
644+ responses. Can be used multiple times to send additional custom response
604645 headers. Headers that are sent automatically by the server (for instance
605646 Content-Type) will not be overwritten by the server.
606647
@@ -615,13 +656,13 @@ Security considerations
615656.. index :: pair: http.server; security
616657
617658:class: `SimpleHTTPRequestHandler ` will follow symbolic links when handling
618- requests, this makes it possible for files outside of the specified directory
659+ requests which makes it possible for files outside of the specified directory
619660to be served.
620661
621662Methods :meth: `BaseHTTPRequestHandler.send_header ` and
622663:meth: `BaseHTTPRequestHandler.send_response_only ` assume sanitized input
623664and do not perform input validation such as checking for the presence of CRLF
624- sequences. Untrusted input may result in HTTP Header injection attacks.
665+ sequences. Untrusted input may result in HTTP header injection attacks.
625666
626667Earlier versions of Python did not scrub control characters from the
627668log messages emitted to stderr from ``python -m http.server `` or the
0 commit comments