1
0
mirror of https://github.com/etesync/server synced 2024-12-29 10:48:07 +00:00

msgpack.py: allow pydantic BaseModel in content

This commit is contained in:
Tal Leibman 2020-12-25 11:10:43 +02:00 committed by Tom Hacohen
parent c1534f6587
commit 25cb4fec0c

View File

@ -1,6 +1,7 @@
import typing as t
import msgpack
from fastapi.routing import APIRoute, get_request_handler
from pydantic import BaseModel
from starlette.requests import Request
from starlette.responses import Response
@ -19,6 +20,8 @@ class MsgpackResponse(Response):
media_type = "application/msgpack"
def render(self, content: t.Any) -> bytes:
if isinstance(content, BaseModel):
content = content.dict()
return msgpack.packb(content, use_bin_type=True)