fhttpy/modules/http/file-handlers/text.py

27 lines
628 B
Python
Raw Normal View History

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