fhttpy/modules/http/file-handlers/text.py
2022-06-21 03:30:07 +02:00

30 lines
677 B
Python

global handleText
def handleText(env):
filePath = env["fPath"]
data = b""
lastModified = None
with fileLock:
with open(env["fPath"],"rb") as textFile:
data = textFile.read()
try:
lastModified = os.path.getmtime(filePath)
except:
pass
headers = {
"Content-Type": mimetypesText[env["fileExt"]]+ "; charset=UTF-8",
"Accept-Ranges": "none",
"Date": env["requestTimeFormatted"]
}
if lastModified != None:
headers["Last-Modified"] = email.utils.formatdate(lastModified).replace("-0000","GMT")
simpleResponse(
env["self"].connection,"200 OK",headers,data
)
for t in mimetypesText:
fileHandlers[t] = handleText
indexFiles.append("index.html")