From 797891d6cf452f6b77306a8efa33f3514ca2dff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kyle=20Bl=C3=B6m?= Date: Tue, 14 Feb 2017 09:27:39 -0800 Subject: [PATCH] Added raw response for bag o' bytes responses --- sanic/response.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sanic/response.py b/sanic/response.py index 2f5c0135..47b0f407 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 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_bytes=body, status=status, headers=headers, + content_type=content_type) def html(body, status=200, headers=None):