Discard Last-Modified on error, other fixes
This commit is contained in:
parent
333d3a3782
commit
d20f3b5434
@ -4,14 +4,13 @@ def handleBinary(env):
|
|||||||
fileExt = env["fileExt"]
|
fileExt = env["fileExt"]
|
||||||
connection = env["self"].connection
|
connection = env["self"].connection
|
||||||
length = 0
|
length = 0
|
||||||
lastModified = 0
|
lastModified = None
|
||||||
with fileLock:
|
with fileLock:
|
||||||
length = os.path.getsize(filePath)
|
length = os.path.getsize(filePath)
|
||||||
try:
|
try:
|
||||||
lastModified = os.path.getmtime(filePath)
|
lastModified = os.path.getmtime(filePath)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
lastModified = email.utils.formatdate(lastModified).replace("-0000","GMT")
|
|
||||||
|
|
||||||
rangeDefined = False
|
rangeDefined = False
|
||||||
rangeStart = 0
|
rangeStart = 0
|
||||||
@ -28,23 +27,22 @@ def handleBinary(env):
|
|||||||
if fileExt in mimetypesBinary:
|
if fileExt in mimetypesBinary:
|
||||||
mimetype = mimetypesBinary[fileExt]
|
mimetype = mimetypesBinary[fileExt]
|
||||||
|
|
||||||
if not rangeDefined:
|
status = "200 OK"
|
||||||
simpleResponse(connection,"200 OK",{
|
headers = {
|
||||||
"Content-Length": str(length),
|
"Content-Length": str(length),
|
||||||
"Content-Type": mimetype,
|
"Content-Type": mimetype,
|
||||||
"Accept-Ranges": "bytes",
|
"Accept-Ranges": "bytes",
|
||||||
"Date": env["requestTimeFormatted"],
|
"Date": env["requestTimeFormatted"]
|
||||||
"Last-Modified": lastModified
|
}
|
||||||
})
|
|
||||||
else:
|
if lastModified != None:
|
||||||
simpleResponse(connection,"206 Partial Content",{
|
headers["Last-Modified"] = email.utils.formatdate(lastModified).replace("-0000","GMT")
|
||||||
"Content-Range": "bytes " +str(rangeStart)+ "-" +str(rangeEnd - 1)+ "/" +str(length),
|
|
||||||
"Content-Length": str(rangeEnd - rangeStart),
|
if rangeDefined:
|
||||||
"Content-Type": mimetype,
|
status = "206 Partial Content"
|
||||||
"Accept-Ranges": "bytes",
|
headers["Content-Range"] = "bytes " +str(rangeStart)+ "-" +str(rangeEnd - 1)+ "/" +str(length)
|
||||||
"Date": env["requestTimeFormatted"],
|
|
||||||
"Last-Modified": lastModified
|
simpleResponse(connection,status,headers)
|
||||||
})
|
|
||||||
|
|
||||||
cByte = rangeStart
|
cByte = rangeStart
|
||||||
while cByte < rangeEnd:
|
while cByte < rangeEnd:
|
||||||
|
Loading…
Reference in New Issue
Block a user