]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Ensure that HTTPServerRequest.body is a byte string 1285/head
authorfelloak <felloak@gmail.com>
Tue, 23 Dec 2014 08:28:36 +0000 (16:28 +0800)
committerfelloak <felloak@gmail.com>
Tue, 23 Dec 2014 08:28:36 +0000 (16:28 +0800)
HTTPServerRequest.body should be bytes but it is an empty string that
occurs in Python3 when pass no body to HTTPServerRequest.

tornado/httputil.py
tornado/test/httputil_test.py
tornado/wsgi.py

index a3745569cac7cfe85745e1d7ae408d2a413ec232..88389fedfe581d68b9e55a8e0ce0d3306d47662c 100644 (file)
@@ -331,7 +331,7 @@ class HTTPServerRequest(object):
         self.uri = uri
         self.version = version
         self.headers = headers or HTTPHeaders()
-        self.body = body or ""
+        self.body = body or b""
 
         # set remote IP and protocol
         context = getattr(connection, 'context', None)
index 5ca5cf9f335cc50f63b3ae48356fdcb2d4c954e3..adbd17114a138f31a9c29408bd6ad822bc0a7566 100644 (file)
@@ -264,6 +264,10 @@ class HTTPServerRequestTest(unittest.TestCase):
         # more required parameters slip in.
         HTTPServerRequest(uri='/')
 
+    def test_body_is_a_byte_string(self):
+        requets = HTTPServerRequest(uri='/')
+        self.assertIsInstance(requets.body, bytes)
+
 
 class ParseRequestStartLineTest(unittest.TestCase):
     METHOD = "GET"
index f3aa66503c3bfadb1b2b0b24cbe8961c70967274..e7e07fbc9cf3e960eebe66b8263f198476a1af35 100644 (file)
@@ -207,7 +207,7 @@ class WSGIAdapter(object):
             body = environ["wsgi.input"].read(
                 int(headers["Content-Length"]))
         else:
-            body = ""
+            body = b""
         protocol = environ["wsgi.url_scheme"]
         remote_ip = environ.get("REMOTE_ADDR", "")
         if environ.get("HTTP_HOST"):