From 39d54467898bec9d0943b96aee1956dc4970ab0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 5 Oct 2016 12:33:02 +0200 Subject: [PATCH] Fixed encoding bug in HTTP request processing, causing weird flask issues If a content type header was present on a multipart form data part it would turn the rewritten body into a unicode instead of a byte array, causing a later conversion to a byte stream to not capture. Fixed both the fact that the rewritten body would turn into unicode by making sure the content type header was provided as byte array and fixed the byte stream conversion to also trigger on unicode instances. Solves #1531 --- src/octoprint/server/util/tornado.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index c167a75f..d551ec9e 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -361,7 +361,7 @@ class UploadStorageFallbackHandler(tornado.web.RequestHandler): file=handle) else: - return dict(name=tornado.escape.utf8(name), content_type=content_type, data=b"") + return dict(name=tornado.escape.utf8(name), content_type=tornado.escape.utf8(content_type), data=b"") def _on_part_data(self, part, data): """ @@ -598,7 +598,7 @@ class WsgiInputContainer(object): # determine the request_body to supply as wsgi.input if body is not None: - if isinstance(body, (bytes, str)): + if isinstance(body, (bytes, str, unicode)): request_body = io.BytesIO(tornado.escape.utf8(body)) else: request_body = body