Ticket #6168: 6168.diff

File 6168.diff, 1.5 KB (added by borko, 4 years ago)
  • twisted/web/http_headers.py

    diff --git a/twisted/web/http_headers.py b/twisted/web/http_headers.py
    index f0790b9..1a93e18 100644
    a b class Headers(object): 
    194194
    195195        @return: C{None}
    196196        """
     197
    197198        if not isinstance(values, list):
    198199            raise TypeError("Header entry %r should be list but found "
    199200                            "instance of %r instead" % (name, type(values)))
     201
     202        if not all(isinstance(n, bytes) for n in name):
     203            raise TypeError("All header elements in %r must be bytes" % name )
     204
    200205        self._rawHeaders[name.lower()] = values
    201206
    202207
  • twisted/web/test/test_http.py

    diff --git a/twisted/web/test/test_http.py b/twisted/web/test/test_http.py
    index f3f2dcc..cc59a23 100644
    a b class RequestTests(unittest.TestCase, ResponseTestMixin): 
    13751375            "Passing non-bytes header values is deprecated since "
    13761376            "Twisted 12.3. Pass only bytes instead.")
    13771377
     1378    def test_nonByteHeaderError(self):
     1379        """
     1380        L{http.Request.write} casts non-bytes header value to bytes
     1381        transparently.
     1382        """
     1383        req = http.Request(DummyChannel(), None)
     1384
     1385        intlist = [int(1), int(2)]
     1386        err = self.assertRaises(TypeError, req.responseHeaders.setRawHeaders, intlist, [10])
     1387        self.assertEqual(str(err), "All header elements in " + intlist.__str__() + " must be bytes")     
    13781388
    13791389    def test_firstWriteHTTP11Chunked(self):
    13801390        """