Skip to content

Commit

Permalink
added a third unpacked element (Content-type)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-balades committed Oct 2, 2021
1 parent 5691655 commit 7620eef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion expross/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from __future__ import absolute_import

from expross.routes import Route
from expross.errors import RouteAlreadyExists, RedirectPlease
from expross.errors import ErrorHandlerExists, ErrorCodeExists
from expross.error import ErrorHandler

Expand Down
16 changes: 10 additions & 6 deletions expross/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,27 @@ def _get_res_and_code(self):
data = self.function()

try:
res, code = data
res, code, content_type = data
except ValueError:
res = data
code = 200
try:
content_type = None
res, code = data
except ValueError:
res = data
code = 200

return res, code
return res, code, content_type

def on_get(self, req: Request, resp: Response):
self._check_for_method("GET")

self.app.req: Request = req
res, code = self._get_res_and_code()
res, code, content_type = self._get_res_and_code()
data, type = get_response(res)

resp.status = code
resp.data = data
resp.content_type = type
resp.content_type = type if content_type is None else content_type

def on_post(self, req: Request, resp: Response):
self._check_for_method("POST")

0 comments on commit 7620eef

Please sign in to comment.