Discard Last-Modified on error, other fixes

This commit is contained in:
Fierelier 2022-06-21 03:29:22 +02:00
parent 333d3a3782
commit d20f3b5434
1 changed files with 17 additions and 19 deletions

View File

@ -4,14 +4,13 @@ def handleBinary(env):
fileExt = env["fileExt"]
connection = env["self"].connection
length = 0
lastModified = 0
lastModified = None
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
@ -28,23 +27,22 @@ def handleBinary(env):
if fileExt in mimetypesBinary:
mimetype = mimetypesBinary[fileExt]
if not rangeDefined:
simpleResponse(connection,"200 OK",{
"Content-Length": str(length),
"Content-Type": mimetype,
"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",
"Date": env["requestTimeFormatted"],
"Last-Modified": lastModified
})
status = "200 OK"
headers = {
"Content-Length": str(length),
"Content-Type": mimetype,
"Accept-Ranges": "bytes",
"Date": env["requestTimeFormatted"]
}
if lastModified != None:
headers["Last-Modified"] = email.utils.formatdate(lastModified).replace("-0000","GMT")
if rangeDefined:
status = "206 Partial Content"
headers["Content-Range"] = "bytes " +str(rangeStart)+ "-" +str(rangeEnd - 1)+ "/" +str(length)
simpleResponse(connection,status,headers)
cByte = rangeStart
while cByte < rangeEnd: