Cleaner datetime API usage.
This commit is contained in:
parent
87b66719e3
commit
a9fc6f451b
1 changed files with 3 additions and 4 deletions
|
@ -10,7 +10,6 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from time import localtime
|
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
|
@ -349,10 +348,10 @@ class HttpHandler(BaseHTTPRequestHandler):
|
||||||
# Parse the If-Modified-Since header to check whether the browser can reuse cached content
|
# Parse the If-Modified-Since header to check whether the browser can reuse cached content
|
||||||
datestr: str = self.headers.get('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT')
|
datestr: str = self.headers.get('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT')
|
||||||
maxage: datetime = datetime.strptime(datestr, '%a, %d %b %Y %H:%M:%S %Z')
|
maxage: datetime = datetime.strptime(datestr, '%a, %d %b %Y %H:%M:%S %Z')
|
||||||
# File modification time in LOCAL time
|
# Get file modification time
|
||||||
filestat: int = int(os.path.getmtime(filepath))
|
filestat: int = int(os.path.getmtime(filepath))
|
||||||
# Create timezone-unaware datetime object and subtract UTC offset
|
# Create UTC datetime object from mtime
|
||||||
fileage: datetime = datetime.fromtimestamp(filestat) - timedelta(seconds=localtime().tm_gmtoff)
|
fileage: datetime = datetime.utcfromtimestamp(filestat)
|
||||||
|
|
||||||
# If the file has not been replaced by a newer version than requested by the client, send a 304 response
|
# If the file has not been replaced by a newer version than requested by the client, send a 304 response
|
||||||
if fileage <= maxage:
|
if fileage <= maxage:
|
||||||
|
|
Loading…
Reference in a new issue