Leave request and response bodies as binary data

Decoding to UTF-8 text is the responsibility of the content-type loader
used in the validator, and should not be done prior.
This commit is contained in:
Correl Roush 2021-01-06 14:50:15 -05:00
parent b69f690d50
commit 4102a14883
4 changed files with 5 additions and 5 deletions

View file

@ -99,7 +99,7 @@ class TestRequestFactory(unittest.TestCase):
full_url_pattern=url,
method="get",
parameters=RequestParameters(query=ImmutableMultiDict(parameters)),
body="",
body=b"",
mimetype="application/x-www-form-urlencoded",
)
openapi_request = TornadoRequestFactory.create(tornado_request)
@ -125,7 +125,7 @@ class TestRequestFactory(unittest.TestCase):
full_url_pattern=url,
method="get",
parameters=RequestParameters(query=ImmutableMultiDict(parameters)),
body="",
body=b"",
mimetype="application/x-www-form-urlencoded",
)
openapi_request = TornadoRequestFactory.create(tornado_request)

View file

@ -66,7 +66,7 @@ class TestResponseFactory(unittest.TestCase):
tornado_request = HTTPRequest(url="http://example.com")
tornado_response = HTTPResponse(request=tornado_request, code=200)
expected = OpenAPIResponse(
data="",
data=b"",
status_code=200,
mimetype="text/html",
)

View file

@ -43,7 +43,7 @@ class TornadoRequestFactory:
parameters=RequestParameters(
query=query_arguments, header=Headers(request.headers.get_all())
),
body=request.body.decode("utf-8") if request.body else "",
body=request.body if request.body else b"",
mimetype=request.headers.get(
"Content-Type", "application/x-www-form-urlencoded"
),

View file

@ -13,7 +13,7 @@ class TornadoResponseFactory:
def create(cls, response: HTTPResponse) -> OpenAPIResponse:
mimetype = response.headers.get("Content-Type", "text/html")
return OpenAPIResponse(
data=response.body.decode("utf-8") if response.body else "",
data=response.body if response.body else b"",
status_code=response.code,
mimetype=mimetype,
)