Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add an index_pages default list to SimpleHTTPRequestHandler and an
optional constructor parameter that allows the default indexes pages
list to be overridden.  This makes it easy to set a new index page name
without having to override send_head.
  • Loading branch information
myronww committed Mar 19, 2022
commit 0d0e089cd4122cc5c22068c96a7d664e8fd2087a
7 changes: 5 additions & 2 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):

"""

index_pages = ["index.html", "index.htm"]
server_version = "SimpleHTTP/" + __version__
extensions_map = _encodings_map_default = {
'.gz': 'application/gzip',
Expand All @@ -643,9 +644,11 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
'.xz': 'application/x-xz',
}

def __init__(self, *args, directory=None, **kwargs):
def __init__(self, *args, directory=None, index_pages=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 Expand Up @@ -689,7 +692,7 @@ def send_head(self):
self.send_header("Content-Length", "0")
self.end_headers()
return None
for index in "index.html", "index.htm":
for index in self.index_pages:
index = os.path.join(path, index)
if os.path.exists(index):
path = index
Expand Down