summaryrefslogtreecommitdiff
path: root/django/utils/http.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils/http.py')
-rw-r--r--django/utils/http.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/django/utils/http.py b/django/utils/http.py
index 4912c9c46a..5ec6e92d28 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -1,4 +1,6 @@
import urllib
+from email.Utils import formatdate
+
from django.utils.encoding import smart_str, force_unicode
from django.utils.functional import allow_lazy
@@ -37,3 +39,29 @@ def urlencode(query, doseq=0):
for k, v in query],
doseq)
+def cookie_date(epoch_seconds=None):
+ """
+ Formats the time to ensure compatibility with Netscape's cookie standard.
+
+ Accepts a floating point number expressed in seconds since the epoch, in
+ UTC - such as that outputted by time.time(). If set to None, defaults to
+ the current time.
+
+ Outputs a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'.
+ """
+ rfcdate = formatdate(epoch_seconds)
+ return '%s-%s-%s GMT' % (rfcdate[:7], rfcdate[8:11], rfcdate[12:25])
+
+def http_date(epoch_seconds=None):
+ """
+ Formats the time to match the RFC1123 date format as specified by HTTP
+ RFC2616 section 3.3.1.
+
+ Accepts a floating point number expressed in seconds since the epoch, in
+ UTC - such as that outputted by time.time(). If set to None, defaults to
+ the current time.
+
+ Outputs a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
+ """
+ rfcdate = formatdate(epoch_seconds)
+ return '%s GMT' % rfcdate[:25]