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:
parent
c1534f6587
commit
25cb4fec0c
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user