Compare commits

...

2 Commits

Author SHA1 Message Date
Fierelier 333d3a3782 Set Accept-Ranges to none for text file handler 2022-06-08 11:21:38 +02:00
Fierelier c6bc9d5aea Add support for Date and Last-Modified headers 2022-06-08 11:21:12 +02:00
2 changed files with 21 additions and 3 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"
"Accept-Ranges": "none",
"Date": env["requestTimeFormatted"],
"Last-Modified": lastModified
},data
)