Ticket #9163: 9163_alt_r9362.diff

File 9163_alt_r9362.diff, 1.1 KB (added by carljm, 7 years ago)

alternative patch for HttpResponse to remove ETag; incl test

  • django/http/__init__.py

     
    360360
    361361    def _set_content(self, value):
    362362        self._container = [value]
     363        del self['ETag']
    363364        self._is_string = True
    364365
    365366    content = property(_get_content, _set_content)
  • tests/regressiontests/httpwrappers/tests.py

     
    444444>>> x.update(y)
    445445>>> x.getlist('a')
    446446[u'1', u'2', u'3', u'4']
     447
     448#
     449# Regression test for #9163: should remove ETag if content is modified
     450#
     451>>> content = 'some content'
     452>>> hash = md5_constructor('some content').hexdigest()
     453>>> r = HttpResponse(content)
     454>>> r['ETag'] = hash
     455>>> r.content = 'new content'
     456>>> r.has_header('ETag')
     457False
     458
    447459"""
    448460
    449461from django.http import QueryDict, HttpResponse
     462from django.utils.hashcompat import md5_constructor
    450463
    451464if __name__ == "__main__":
    452465    import doctest
Back to Top