Skip to content

Commit

Permalink
feat: Allow HTTP response body to be set to Any.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm committed Oct 25, 2022
1 parent 9f9d073 commit 1f87d11
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nitric/faas.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(self, data: bytes, method: str, path: str, params: Dict[str, str],

@property
def json(self) -> Optional[Any]:
"""Attempt the body of the request as JSON, returns None if request body is not JSON"""
"""Get the body of the request as JSON, returns None if request body is not JSON"""
try:
return json.loads(self.body)
except:
Expand All @@ -171,11 +171,14 @@ def body(self):
return self._body

@body.setter
def body(self, value: Union[str, bytes]):
def body(self, value: Union[str, bytes, Any]):
if isinstance(value, str):
self._body = value.encode("utf-8")
else:
elif isinstance(value, bytes):
self._body = value
else:
self._body = json.dumps(value).encode("utf-8")



class HttpContext(TriggerContext):
Expand Down

0 comments on commit 1f87d11

Please sign in to comment.