summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2022-04-21 13:41:30 -0600
committerBert JW Regeer <bertjw@regeer.org>2022-04-21 13:45:41 -0600
commitb6ad056d64b3e269518f87cd33dedaeb95243ba8 (patch)
tree416f168a5123824c499589e02403f7ff9a69f486
parent7a145701f2198dea785c080a86ed0a482d6bc4b5 (diff)
downloadwaitress-b6ad056d64b3e269518f87cd33dedaeb95243ba8.tar.gz
Always encode the responses to utf-8 and set Content-Type
-rw-r--r--src/waitress/utilities.py4
-rw-r--r--tests/test_functional.py10
-rw-r--r--tests/test_task.py8
3 files changed, 11 insertions, 11 deletions
diff --git a/src/waitress/utilities.py b/src/waitress/utilities.py
index 6ae4742..a9d3361 100644
--- a/src/waitress/utilities.py
+++ b/src/waitress/utilities.py
@@ -262,8 +262,8 @@ class Error:
status = "%s %s" % (self.code, self.reason)
body = "%s\r\n\r\n%s" % (self.reason, self.body)
tag = "\r\n\r\n(generated by waitress)"
- body = body + tag
- headers = [("Content-Type", "text/plain")]
+ body = (body + tag).encode("utf-8")
+ headers = [("Content-Type", "text/plain; charset=utf-8")]
return status, headers, body
diff --git a/tests/test_functional.py b/tests/test_functional.py
index 43e9d0c..1dfd889 100644
--- a/tests/test_functional.py
+++ b/tests/test_functional.py
@@ -359,7 +359,7 @@ class EchoTests:
sorted(headers.keys()),
["connection", "content-length", "content-type", "date", "server"],
)
- self.assertEqual(headers["content-type"], "text/plain")
+ self.assertEqual(headers["content-type"], "text/plain; charset=utf-8")
# connection has been closed
self.send_check_error(to_send)
self.assertRaises(ConnectionClosed, read_http, fp)
@@ -381,7 +381,7 @@ class EchoTests:
sorted(headers.keys()),
["connection", "content-length", "content-type", "date", "server"],
)
- self.assertEqual(headers["content-type"], "text/plain")
+ self.assertEqual(headers["content-type"], "text/plain; charset=utf-8")
# connection has been closed
self.send_check_error(to_send)
self.assertRaises(ConnectionClosed, read_http, fp)
@@ -403,7 +403,7 @@ class EchoTests:
sorted(headers.keys()),
["connection", "content-length", "content-type", "date", "server"],
)
- self.assertEqual(headers["content-type"], "text/plain")
+ self.assertEqual(headers["content-type"], "text/plain; charset=utf-8")
# connection has been closed
self.send_check_error(to_send)
self.assertRaises(ConnectionClosed, read_http, fp)
@@ -428,7 +428,7 @@ class EchoTests:
sorted(headers.keys()),
["connection", "content-length", "content-type", "date", "server"],
)
- self.assertEqual(headers["content-type"], "text/plain")
+ self.assertEqual(headers["content-type"], "text/plain; charset=utf-8")
# connection has been closed
self.send_check_error(to_send)
self.assertRaises(ConnectionClosed, read_http, fp)
@@ -1121,7 +1121,7 @@ class TooLargeTests:
self.assertline(line, "413", "Request Entity Too Large", "HTTP/1.1")
cl = int(headers["content-length"])
self.assertEqual(cl, len(response_body))
- self.assertEqual(headers["content-type"], "text/plain")
+ self.assertEqual(headers["content-type"], "text/plain; charset=utf-8")
# connection has been closed
self.send_check_error(to_send)
self.assertRaises(ConnectionClosed, read_http, fp)
diff --git a/tests/test_task.py b/tests/test_task.py
index cc579b0..47868e1 100644
--- a/tests/test_task.py
+++ b/tests/test_task.py
@@ -869,7 +869,7 @@ class TestErrorTask(unittest.TestCase):
self.assertEqual(lines[0], b"HTTP/1.0 432 Too Ugly")
self.assertEqual(lines[1], b"Connection: close")
self.assertEqual(lines[2], b"Content-Length: 43")
- self.assertEqual(lines[3], b"Content-Type: text/plain")
+ self.assertEqual(lines[3], b"Content-Type: text/plain; charset=utf-8")
self.assertTrue(lines[4])
self.assertEqual(lines[5], b"Server: waitress")
self.assertEqual(lines[6], b"Too Ugly")
@@ -885,7 +885,7 @@ class TestErrorTask(unittest.TestCase):
self.assertEqual(lines[0], b"HTTP/1.1 432 Too Ugly")
self.assertEqual(lines[1], b"Connection: close")
self.assertEqual(lines[2], b"Content-Length: 43")
- self.assertEqual(lines[3], b"Content-Type: text/plain")
+ self.assertEqual(lines[3], b"Content-Type: text/plain; charset=utf-8")
self.assertTrue(lines[4])
self.assertEqual(lines[5], b"Server: waitress")
self.assertEqual(lines[6], b"Too Ugly")
@@ -902,7 +902,7 @@ class TestErrorTask(unittest.TestCase):
self.assertEqual(lines[0], b"HTTP/1.1 432 Too Ugly")
self.assertEqual(lines[1], b"Connection: close")
self.assertEqual(lines[2], b"Content-Length: 43")
- self.assertEqual(lines[3], b"Content-Type: text/plain")
+ self.assertEqual(lines[3], b"Content-Type: text/plain; charset=utf-8")
self.assertTrue(lines[4])
self.assertEqual(lines[5], b"Server: waitress")
self.assertEqual(lines[6], b"Too Ugly")
@@ -919,7 +919,7 @@ class TestErrorTask(unittest.TestCase):
self.assertEqual(lines[0], b"HTTP/1.1 432 Too Ugly")
self.assertEqual(lines[1], b"Connection: close")
self.assertEqual(lines[2], b"Content-Length: 43")
- self.assertEqual(lines[3], b"Content-Type: text/plain")
+ self.assertEqual(lines[3], b"Content-Type: text/plain; charset=utf-8")
self.assertTrue(lines[4])
self.assertEqual(lines[5], b"Server: waitress")
self.assertEqual(lines[6], b"Too Ugly")