summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Gajdusek <atx@atx.name>2017-11-05 13:59:45 +0100
committerJosef Gajdusek <atx@atx.name>2017-11-05 20:15:33 +0100
commit443491630426c79befcc19f3c3bb4e654a6a25e5 (patch)
treeb3b27df9f4b2577d74cdd6fea22039d2f9d6e229
parentdb8da3a6aab1142ea0694963eb9afb5026c3c467 (diff)
downloadbottle-443491630426c79befcc19f3c3bb4e654a6a25e5.tar.gz
Fix Last-Modifed and Date header formats in static_file for non-english locales
time.strftime produces locale-dependent date format. At best, this lead to invalid dates being produced, e. g: 'Ne, 05 lis 2017 12:58:28 GMT'. At worst, this lead to encoding crashes for dates like 'Út, 31 říj 2017 12:58:28 GMT'
-rwxr-xr-xbottle.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/bottle.py b/bottle.py
index bda20e6..0d43d7c 100755
--- a/bottle.py
+++ b/bottle.py
@@ -2884,9 +2884,9 @@ def static_file(filename, root,
stats = os.stat(filename)
headers['Content-Length'] = clen = stats.st_size
- lm = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(stats.st_mtime))
- headers['Last-Modified'] = lm
- headers['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
+ headers['Last-Modified'] = email.utils.formatdate(stats.st_mtime,
+ usegmt=True)
+ headers['Date'] = email.utils.formatdate(time.time(), usegmt=True)
getenv = request.environ.get