Ticket #4022: strict-setRawHeaders-4022.diff

File strict-setRawHeaders-4022.diff, 1.1 KB (added by djfroofy, 7 years ago)

Patch to only accept list value in setRawHeaders

  • twisted/web/test/test_http_headers.py

     
    3737        self.assertTrue(h.hasHeader("Test"))
    3838        self.assertEqual(h.getRawHeaders("test"), rawValue)
    3939
     40    def test_rawHeadersTypeChecking(self):
     41        """
     42        L{Headers.setRawHeaders} requires values to be of type list.
     43        """
     44        h = Headers()
     45        self.assertRaises(TypeError, h.setRawHeaders, {'Foo': 'bar'})
    4046
    4147    def test_addRawHeader(self):
    4248        """
  • twisted/web/http_headers.py

     
    196196
    197197        @return: C{None}
    198198        """
     199        if not isinstance(values, list):
     200            raise TypeError("Header entry `%r' should be list but found"
     201                            " %r instead" % (name, type(values)))
    199202        self._rawHeaders[name.lower()] = values
    200203
    201204