From c6bc9d5aea284634773eb485d3b8c629f0c1c290 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 8 Jun 2022 11:21:12 +0200 Subject: [PATCH] Add support for Date and Last-Modified headers --- modules/http/file-handlers/binary.py | 14 ++++++++++++-- modules/http/file-handlers/text.py | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/http/file-handlers/binary.py b/modules/http/file-handlers/binary.py index 05605c0..806d6ef 100644 --- a/modules/http/file-handlers/binary.py +++ b/modules/http/file-handlers/binary.py @@ -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 diff --git a/modules/http/file-handlers/text.py b/modules/http/file-handlers/text.py index cc75142..1e6ab47 100644 --- a/modules/http/file-handlers/text.py +++ b/modules/http/file-handlers/text.py @@ -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 )