Add support for Date and Last-Modified headers

This commit is contained in:
Fierelier 2022-06-08 11:21:12 +02:00
parent ef657a3436
commit c6bc9d5aea
2 changed files with 20 additions and 2 deletions

View File

@ -4,8 +4,14 @@ def handleBinary(env):
fileExt = env["fileExt"]
connection = env["self"].connection
length = 0
lastModified = 0
with fileLock:
length = os.path.getsize(filePath)
try:
lastModified = os.path.getmtime(filePath)
except:
pass
lastModified = email.utils.formatdate(lastModified).replace("-0000","GMT")
rangeDefined = False
rangeStart = 0
@ -26,14 +32,18 @@ def handleBinary(env):
simpleResponse(connection,"200 OK",{
"Content-Length": str(length),
"Content-Type": mimetype,
"Accept-Ranges": "bytes"
"Accept-Ranges": "bytes",
"Date": env["requestTimeFormatted"],
"Last-Modified": lastModified
})
else:
simpleResponse(connection,"206 Partial Content",{
"Content-Range": "bytes " +str(rangeStart)+ "-" +str(rangeEnd - 1)+ "/" +str(length),
"Content-Length": str(rangeEnd - rangeStart),
"Content-Type": mimetype,
"Accept-Ranges": "bytes"
"Accept-Ranges": "bytes",
"Date": env["requestTimeFormatted"],
"Last-Modified": lastModified
})
cByte = rangeStart

View File

@ -1,15 +1,23 @@
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": "bytes"
"Date": env["requestTimeFormatted"],
"Last-Modified": lastModified
},data
)