Commits

Robert Brewer committed 5fb9b59

New test for non-string response header value.

  • Participants
  • Parent commits 725c872

Comments (0)

Files changed (2)

File cheroot/test/test_wsgi.py

         def baz(environ, start_response):
             status = 200
             response_headers = [('Content-type', 'text/plain')]
-            # This should fail because status is not bytes
+            # This should fail because status is not a str
+            start_response(status, response_headers)
+            return [ntob('Hello world')]
+
+        def qoph(environ, start_response):
+            status = '200 OK'
+            response_headers = [('Content-type', 5)]
+            # This should fail because the response header value is not a str
             start_response(status, response_headers)
             return [ntob('Hello world')]
 
             '/foo': foo,
             '/bar': bar,
             '/baz': baz,
+            '/qoph': qoph,
             })
     setup_server = classmethod(setup_server)
 
         self.assertInLog(
             "WSGI response status is not of type str.")
 
+    def test_nonstring_header_value(self):
+        self.getPage("/qoph")
+        self.assertStatus(500)
+        self.assertInLog(
+            "WSGI response header value %s is not of type str." % repr(5))
+

File cheroot/wsgi.py

 
         for k, v in headers:
             if not isinstance(k, str):
-                raise TypeError("WSGI response header key %r is not of type str." % k)
+                raise TypeError(
+                    "WSGI response header key %s is not of type str." %
+                    repr(k))
             if not isinstance(v, str):
-                raise TypeError("WSGI response header value %r is not of type str." % v)
+                raise TypeError(
+                    "WSGI response header value %s is not of type str." %
+                    repr(v))
             if k.lower() == 'content-length':
                 self.remaining_bytes_out = int(v)
             self.req.outheaders.append((ntob(k), ntob(v)))