Skip to content

Commit

Permalink
Merge pull request #1285 from lwzm/master
Browse files Browse the repository at this point in the history
Ensure that HTTPServerRequest.body is a byte string
  • Loading branch information
bdarnell committed Jan 10, 2015
2 parents dca3f6b + 429aae4 commit eab34a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tornado/httputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def __init__(self, method=None, uri=None, version="HTTP/1.0", headers=None,
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)
Expand Down
4 changes: 4 additions & 0 deletions tornado/test/httputil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def test_default_constructor(self):
# 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"
Expand Down
2 changes: 1 addition & 1 deletion tornado/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def __call__(self, environ, start_response):
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"):
Expand Down

0 comments on commit eab34a9

Please sign in to comment.