FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-91219: http - use subclassing to override index_pages attribute by ethanfurman · Pull Request #100731 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions Doc/library/http.server.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ the current directory::
print("serving at port", PORT)
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:

:mod:`http.server` can also be invoked directly using the :option:`-m`
Expand Down
6 changes: 2 additions & 4 deletions Lib/http/server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -652,20 +652,18 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):

"""

index_pages = ["index.html", "index.htm"]
server_version = "SimpleHTTP/" + __version__
index_pages = ("index.html", "index.htm")
extensions_map = _encodings_map_default = {
'.gz': 'application/gzip',
'.Z': 'application/octet-stream',
'.bz2': 'application/x-bzip2',
'.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:
directory = os.getcwd()
if index_pages is not None:
self.index_pages = index_pages
self.directory = os.fspath(directory)
super().__init__(*args, **kwargs)

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Change ``SimpleHTTPRequestHandler`` to support subclassing to provide a
different set of index file names instead of using ``__init__`` parameters.

Back | FazBrowse Home | New Git URL