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

27 lines
628 B
Python

global handleText
def handleText(env):
data = b""
lastModified = 0
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")
simpleResponse(
env["self"].connection,"200 OK",
{
"Content-Type": mimetypesText[env["fileExt"]]+ "; charset=UTF-8",
"Accept-Ranges": "none",
"Date": env["requestTimeFormatted"],
"Last-Modified": lastModified
},data
)
for t in mimetypesText:
fileHandlers[t] = handleText
indexFiles.append("index.html")