diff --git a/sanic/response.py b/sanic/response.py index 7ab6fc52..d98a9988 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -154,15 +154,32 @@ def json(body, status=200, headers=None, **kwargs): status=status, content_type="application/json") -def text(body, status=200, headers=None): +def text(body, status=200, headers=None, + content_type="text/plain; charset=utf-8"): """ Returns response object with body in text format. :param body: Response data to be encoded. :param status: Response code. :param headers: Custom Headers. + :param content_type: + the content type (string) of the response """ return HTTPResponse(body, status=status, headers=headers, - content_type="text/plain; charset=utf-8") + content_type=content_type) + + +def raw(body, status=200, headers=None, + content_type="application/octet-stream"): + """ + Returns response object without encoding the body. + :param body: Response data. + :param status: Response code. + :param headers: Custom Headers. + :param content_type: + the content type (string) of the response + """ + return HTTPResponse(body_bytes=body, status=status, headers=headers, + content_type=content_type) def html(body, status=200, headers=None):