Ticket #4119: ticket4119.diff
File ticket4119.diff, 4.8 KB (added by , 17 years ago) |
---|
-
django/core/servers/basehttp.py
9 9 10 10 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer 11 11 from types import ListType, StringType 12 import os, re, sys, time, urllib12 import os, re, email.utils, sys, urllib 13 13 14 14 __version__ = "0.1" 15 15 __all__ = ['WSGIServer','WSGIRequestHandler','demo_app'] … … 370 370 self._write('HTTP/%s %s\r\n' % (self.http_version,self.status)) 371 371 if 'Date' not in self.headers: 372 372 self._write( 373 'Date: %s\r\n' % time.asctime(time.gmtime(time.time()))373 'Date: %s\r\n' % email.utils.formatdate()[:26] + "GMT" 374 374 ) 375 375 if self.server_software and 'Server' not in self.headers: 376 376 self._write('Server: %s\r\n' % self.server_software) -
django/contrib/sessions/middleware.py
2 2 from django.contrib.sessions.models import Session 3 3 from django.core.exceptions import SuspiciousOperation 4 4 from django.utils.cache import patch_vary_headers 5 import datetime 5 import datetime, email.utils, time 6 6 7 7 TEST_COOKIE_NAME = 'testcookie' 8 8 TEST_COOKIE_VALUE = 'worked' … … 97 97 expires = None 98 98 else: 99 99 max_age = settings.SESSION_COOKIE_AGE 100 expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT") 100 rfcdate = email.utils.formatdate(time.time() 101 + settings.SESSION_COOKIE_AGE) 102 # Fixed length date must have '-' separation in the format DD-MMM-YYYY 103 # for compliance with Netscape cookie standard 104 expires = (rfcdate[:7] + "-" + rfcdate[8:11] 105 + "-" + rfcdate[12:26] + "GMT") 101 106 new_session = Session.objects.save(session_key, request.session._session, 102 107 datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE)) 103 108 response.set_cookie(settings.SESSION_COOKIE_NAME, session_key, -
django/utils/cache.py
17 17 "Accept-language" header. 18 18 """ 19 19 20 import datetime, md5, re20 import email.utils, md5, re, time 21 21 from django.conf import settings 22 22 from django.core.cache import cache 23 23 … … 43 43 return (t[0].lower().replace('-', '_'), True) 44 44 45 45 def dictvalue(t): 46 if t[1] ==True:46 if t[1] is True: 47 47 return t[0] 48 48 else: 49 49 return t[0] + '=' + str(t[1]) … … 72 72 """ 73 73 if cache_timeout is None: 74 74 cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS 75 now = datetime.datetime.utcnow() 75 if cache_timeout < 0: 76 cache_timeout = 0 # Can't have max-age negative 76 77 if not response.has_header('ETag'): 77 78 response['ETag'] = md5.new(response.content).hexdigest() 78 79 if not response.has_header('Last-Modified'): 79 response['Last-Modified'] = now.strftime('%a, %d %b %Y %H:%M:%S GMT')80 response['Last-Modified'] = email.utils.formatdate()[:26] + "GMT" 80 81 if not response.has_header('Expires'): 81 expires = now + datetime.timedelta(0, cache_timeout) 82 response['Expires'] = expires.strftime('%a, %d %b %Y %H:%M:%S GMT') 83 if cache_timeout < 0: 84 cache_timeout = 0 # Can't have max-age negative 82 response['Expires'] = email.utils.formatdate(time.time() 83 + cache_timeout)[:26] + "GMT" 85 84 patch_cache_control(response, max_age=cache_timeout) 86 85 87 86 def add_never_cache_headers(response): -
django/middleware/http.py
1 import datetime1 import email.utils 2 2 3 3 class ConditionalGetMiddleware(object): 4 4 """ … … 11 11 Also sets the Date and Content-Length response-headers. 12 12 """ 13 13 def process_response(self, request, response): 14 now = datetime.datetime.utcnow() 15 response['Date'] = now.strftime('%a, %d %b %Y %H:%M:%S GMT') 14 response['Date'] = email.utils.formatdate()[:26] + "GMT" 16 15 if not response.has_header('Content-Length'): 17 16 response['Content-Length'] = str(len(response.content)) 18 17