diff --git a/Lib/http/server.py b/Lib/http/server.py
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -105,6 +105,7 @@
DEFAULT_ERROR_MESSAGE = """\
+
Error response
@@ -734,10 +735,15 @@
list.sort(key=lambda a: a.lower())
r = []
displaypath = html.escape(urllib.parse.unquote(self.path))
- r.append('')
- r.append("\nDirectory listing for %s\n" % displaypath)
- r.append("\nDirectory listing for %s
\n" % displaypath)
- r.append("
\n\n")
+ enc = sys.getfilesystemencoding()
+ title = 'Directory listing for %s' % displaypath
+ r.append('')
+ r.append("\n\n%s" % title)
+ r.append('\n' % enc)
+ r.append("\n%s
" % title)
+ r.append("
\n")
for name in list:
fullname = os.path.join(path, name)
displayname = linkname = name
@@ -748,11 +754,10 @@
if os.path.islink(fullname):
displayname = name + "@"
# Note: a link to a directory displays with @ and links with /
- r.append('- %s\n'
+ r.append('
- %s
'
% (urllib.parse.quote(linkname), html.escape(displayname)))
r.append("
\n
\n\n\n")
- enc = sys.getfilesystemencoding()
- encoded = ''.join(r).encode(enc)
+ encoded = '\n'.join(r).encode(enc)
f = io.BytesIO()
f.write(encoded)
f.seek(0)