diff --git a/modules/http/file-handlers/binary.py b/modules/http/file-handlers/binary.py index 806d6ef..889ba19 100644 --- a/modules/http/file-handlers/binary.py +++ b/modules/http/file-handlers/binary.py @@ -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: