Merge pull request #1399 from easyteacher/develop

Make last_modified and if_date timezone-aware (Fix #1398)
This commit is contained in:
Saptak Sengupta 2021-09-04 00:13:12 +05:30 committed by GitHub
commit 1b5b6a6b71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,7 @@ import sys
import tempfile
import zipfile
import mimetypes
from datetime import datetime
from datetime import datetime, timezone
from flask import Response, request, render_template, make_response, abort
from unidecode import unidecode
from werkzeug.http import parse_date, http_date
@ -127,7 +127,7 @@ class ShareModeWeb(SendBaseModeWeb):
self.download_etag = None
self.gzip_etag = None
self.last_modified = datetime.utcnow()
self.last_modified = datetime.now(tz=timezone.utc)
def define_routes(self):
"""
@ -285,6 +285,8 @@ class ShareModeWeb(SendBaseModeWeb):
if_unmod = request.headers.get("If-Unmodified-Since")
if if_unmod:
if_date = parse_date(if_unmod)
if if_date and not if_date.tzinfo:
if_date = if_date.replace(tzinfo=timezone.utc) # Compatible with Flask < 2.0.0
if if_date and if_date > last_modified:
abort(412)
elif range_header is None: