Add support for Date and Last-Modified headers
This commit is contained in:
parent
ef657a3436
commit
c6bc9d5aea
@ -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
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user