Add handler for directories
This commit is contained in:
parent
305e9a4307
commit
a883140db0
41
modules/http/file-handlers/dir.py
Normal file
41
modules/http/file-handlers/dir.py
Normal file
@ -0,0 +1,41 @@
|
||||
global handleDir
|
||||
def handleDir(env):
|
||||
filePath = env["fPath"]
|
||||
|
||||
simpleResponse(
|
||||
env["self"].connection,"200 OK",{
|
||||
"Content-Type": "text/html; charset=UTF-8",
|
||||
"Accept-Ranges": "none",
|
||||
"Date": env["requestTimeFormatted"]
|
||||
}
|
||||
)
|
||||
|
||||
dirList = []
|
||||
fileList = []
|
||||
|
||||
with fileLock:
|
||||
for root,dirs,files in os.walk(filePath):
|
||||
for file in dirs: dirList.append(p(root,file).replace(filePath + os.path.sep,"",1).replace(os.path.sep,"/") + "/")
|
||||
for file in files: fileList.append(p(root,file).replace(filePath + os.path.sep,"",1).replace(os.path.sep,"/"))
|
||||
break
|
||||
|
||||
dirList.sort(key=str.lower)
|
||||
fileList.sort(key=str.lower)
|
||||
|
||||
env["self"].connection.sendall(('''\
|
||||
<html>
|
||||
<head>
|
||||
<title>''' +html.escape(env["lPath"])+ '''</title>
|
||||
</head>
|
||||
<body>''').encode("utf-8"))
|
||||
|
||||
env["self"].connection.sendall(('''<a href="..">..</a><br>\n''').encode("utf-8"))
|
||||
for l in [dirList,fileList]:
|
||||
for lfile in l:
|
||||
env["self"].connection.sendall(('''<a href="''' +html.escape(lfile)+ '''">''' +html.escape(lfile)+ '''</a><br>\n''').encode("utf-8"))
|
||||
|
||||
env["self"].connection.sendall(('''\
|
||||
</body>
|
||||
</html>''').encode("utf-8"))
|
||||
|
||||
fileHandlers[".d"] = handleDir
|
@ -6,6 +6,7 @@
|
||||
# File handlers:
|
||||
./file-handlers/mimetypes.py # List of file endings and the mimetypes they belong to
|
||||
./file-handlers/binary.py # Images, video, audio, executables, etc...
|
||||
./file-handlers/dir.py # Directories
|
||||
./file-handlers/text.py # HTML, XML, TXT, etc...
|
||||
./file-handlers/pyp.py # pyp, fhttpy's script format
|
||||
./file-handlers/htaccess.py # .fhtpyaccess - can be used to override handlers on an entire folder
|
Loading…
Reference in New Issue
Block a user