Open ca34ab3b-442b-4c73-80e7-bca5c120948d opened 6 years ago
In http.server and SimpleHTTPRequestHandler - the send_head function is hard-coded to treat index.html and index.htm as files to return in a directory - if neither of those files are present, it lists the directory.
It would be very nice to be able to specify other files to use as a directory index, similar to the DirectoryIndex directive from Apache.
I think it'd be straight forward to add some kind of list you could set, just like you can modify extensions_map to include other types of MIME types.
Would it be OK to just add a directory_index list with index.html and index.htm on by default that people could do like Handler.directory_index.append("index.htmlx") in their setup? Or would such an API be better with some kind of helper?
Thank you for the report and for the patch!
What's your use case? I understand the need for it for httpd, but as someone who uses http.server daily, I can't think of a use case that I'd find this feature useful. Note that even the example in your message and the test in the patch use artificial file names :)
Handler.directory_index.append("index.htmlx") API doesn't look good to me. It would be nice to subclass it, but that would make http.server less usable (especially if you run it via "python -m http.server")
I suggest closing this as 'rejected' (sorry!)
I think my use case was Sharepoint and static site generators - Sharepoint can serve a tree of .aspx files as raw HTML, but maddeningly not .html files. The site generator we used spit out a fairly complicated site where the internal links point at directories counting on the fact that it is served correctly by the directoryindex handler. The site generator spits out .aspx but http.server can't serve them.
A directory full of .xhtml files would have similar problems, which certainly still exist in the wild.
The example in the test was named index.test because it's creating files on the disk in the test, shared by other parts of the test, and I wanted to be clear about what it was. It was not intended to be an example use case.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['3.7', 'library']
title = 'Add configurable DirectoryIndex to http.server'
updated_at =
user = 'https://github.com/epaulson'
```
bugs.python.org fields:
```python
activity =
actor = 'epaulson'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation =
creator = 'epaulson'
dependencies = []
files = []
hgrepos = []
issue_num = 32628
keywords = ['patch']
message_count = 3.0
messages = ['310468', '344129', '344137']
nosy_count = 2.0
nosy_names = ['berker.peksag', 'epaulson']
pr_nums = ['5308']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue32628'
versions = ['Python 3.7']
```