mirror of
https://github.com/python/cpython.git
synced 2025-09-19 07:00:59 +00:00
gh-91219: http - use subclassing to override index_pages attribute (GH-100731)
Remove previously added parameter to `__init__`, and recommend subclassing to modify the `index_pages` attribute instead.
This commit is contained in:
parent
64ed609c53
commit
a286caa937
3 changed files with 9 additions and 4 deletions
|
@ -413,6 +413,11 @@ the current directory::
|
||||||
print("serving at port", PORT)
|
print("serving at port", PORT)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
:class:`SimpleHTTPRequestHandler` can also be subclassed to enhance behavior,
|
||||||
|
such as using different index file names by overriding the class attribute
|
||||||
|
:attr:`index_pages`.
|
||||||
|
|
||||||
.. _http-server-cli:
|
.. _http-server-cli:
|
||||||
|
|
||||||
:mod:`http.server` can also be invoked directly using the :option:`-m`
|
:mod:`http.server` can also be invoked directly using the :option:`-m`
|
||||||
|
|
|
@ -652,8 +652,8 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
index_pages = ["index.html", "index.htm"]
|
|
||||||
server_version = "SimpleHTTP/" + __version__
|
server_version = "SimpleHTTP/" + __version__
|
||||||
|
index_pages = ("index.html", "index.htm")
|
||||||
extensions_map = _encodings_map_default = {
|
extensions_map = _encodings_map_default = {
|
||||||
'.gz': 'application/gzip',
|
'.gz': 'application/gzip',
|
||||||
'.Z': 'application/octet-stream',
|
'.Z': 'application/octet-stream',
|
||||||
|
@ -661,11 +661,9 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||||
'.xz': 'application/x-xz',
|
'.xz': 'application/x-xz',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, directory=None, index_pages=None, **kwargs):
|
def __init__(self, *args, directory=None, **kwargs):
|
||||||
if directory is None:
|
if directory is None:
|
||||||
directory = os.getcwd()
|
directory = os.getcwd()
|
||||||
if index_pages is not None:
|
|
||||||
self.index_pages = index_pages
|
|
||||||
self.directory = os.fspath(directory)
|
self.directory = os.fspath(directory)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Change ``SimpleHTTPRequestHandler`` to support subclassing to provide a
|
||||||
|
different set of index file names instead of using ``__init__`` parameters.
|
Loading…
Add table
Add a link
Reference in a new issue