From 5c78adf9b91ba299ddbf513716b7db9240ee0d4a Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 14 Feb 2014 02:26:09 +0200 Subject: [PATCH] Use email.utils.formatdate in gunicorn.util.http_date. There is a also an open issue for CPython: http://bugs.python.org/issue747320 --- THANKS | 1 + gunicorn/util.py | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/THANKS b/THANKS index fb3a91ab..1570cf2f 100644 --- a/THANKS +++ b/THANKS @@ -71,3 +71,4 @@ keakon Xie Shi Steven Cummings Malthe Borch +Berker Peksag diff --git a/gunicorn/util.py b/gunicorn/util.py index 8a95e2e0..de0ef613 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -4,6 +4,7 @@ # See the NOTICE for more information. +import email.utils import fcntl import io import os @@ -34,11 +35,6 @@ CHUNK_SIZE = (16 * 1024) MAX_BODY = 1024 * 132 -weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] -monthname = [None, - 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] - # Server and Date aren't technically hop-by-hop # headers, but they are in the purview of the # origin server which the WSGI spec says we should @@ -400,11 +396,7 @@ def http_date(timestamp=None): """Return the current date and time formatted for a message header.""" if timestamp is None: timestamp = time.time() - year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp) - s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % ( - weekdayname[wd], - day, monthname[month], year, - hh, mm, ss) + s = email.utils.formatdate(timestamp, localtime=False, usegmt=True) return s