Ticket #4119: ticket4119.diff

File ticket4119.diff, 4.8 KB (added by Chris Bennett <chrisrbennett@…>, 8 years ago)

fixes for this ticket

  • django/core/servers/basehttp.py

     
    99
    1010from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
    1111from types import ListType, StringType
    12 import os, re, sys, time, urllib
     12import os, re, email.utils, sys, urllib
    1313
    1414__version__ = "0.1"
    1515__all__ = ['WSGIServer','WSGIRequestHandler','demo_app']
     
    370370                self._write('HTTP/%s %s\r\n' % (self.http_version,self.status))
    371371                if 'Date' not in self.headers:
    372372                    self._write(
    373                         'Date: %s\r\n' % time.asctime(time.gmtime(time.time()))
     373                        'Date: %s\r\n' % email.utils.formatdate()[:26] + "GMT"
    374374                    )
    375375                if self.server_software and 'Server' not in self.headers:
    376376                    self._write('Server: %s\r\n' % self.server_software)
  • django/contrib/sessions/middleware.py

     
    22from django.contrib.sessions.models import Session
    33from django.core.exceptions import SuspiciousOperation
    44from django.utils.cache import patch_vary_headers
    5 import datetime
     5import datetime, email.utils, time
    66
    77TEST_COOKIE_NAME = 'testcookie'
    88TEST_COOKIE_VALUE = 'worked'
     
    9797                    expires = None
    9898                else:
    9999                    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")
    101106                new_session = Session.objects.save(session_key, request.session._session,
    102107                    datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))
    103108                response.set_cookie(settings.SESSION_COOKIE_NAME, session_key,
  • django/utils/cache.py

     
    1717"Accept-language" header.
    1818"""
    1919
    20 import datetime, md5, re
     20import email.utils, md5, re, time
    2121from django.conf import settings
    2222from django.core.cache import cache
    2323
     
    4343            return (t[0].lower().replace('-', '_'), True)
    4444
    4545    def dictvalue(t):
    46         if t[1] == True:
     46        if t[1] is True:
    4747            return t[0]
    4848        else:
    4949            return t[0] + '=' + str(t[1])
     
    7272    """
    7373    if cache_timeout is None:
    7474        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
    7677    if not response.has_header('ETag'):
    7778        response['ETag'] = md5.new(response.content).hexdigest()
    7879    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"
    8081    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"
    8584    patch_cache_control(response, max_age=cache_timeout)
    8685
    8786def add_never_cache_headers(response):
  • django/middleware/http.py

     
    1 import datetime
     1import email.utils
    22
    33class ConditionalGetMiddleware(object):
    44    """
     
    1111    Also sets the Date and Content-Length response-headers.
    1212    """
    1313    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"
    1615        if not response.has_header('Content-Length'):
    1716            response['Content-Length'] = str(len(response.content))
    1817
Back to Top