mirror of
https://github.com/g0ldyy/comet.git
synced 2026-01-12 01:16:12 +01:00
fix: CachedJSONResponse overwrites body after init
This commit is contained in:
+8
-10
@@ -3,7 +3,6 @@ from typing import Any, Optional
|
|||||||
|
|
||||||
import orjson
|
import orjson
|
||||||
from fastapi import Request, Response
|
from fastapi import Request, Response
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
|
|
||||||
from comet.core.models import settings
|
from comet.core.models import settings
|
||||||
|
|
||||||
@@ -116,7 +115,7 @@ def check_etag_match(request: Request, etag: str):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class CachedJSONResponse(JSONResponse):
|
class CachedJSONResponse(Response):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
content: Any,
|
content: Any,
|
||||||
@@ -127,18 +126,17 @@ class CachedJSONResponse(JSONResponse):
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
body = orjson.dumps(content)
|
body = orjson.dumps(content)
|
||||||
|
super().__init__(
|
||||||
super().__init__(content=content, status_code=status_code, **kwargs)
|
content=body,
|
||||||
|
status_code=status_code,
|
||||||
self.body = body
|
media_type="application/json",
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
if cache_control:
|
if cache_control:
|
||||||
self.headers["Cache-Control"] = cache_control.build()
|
self.headers["Cache-Control"] = cache_control.build()
|
||||||
|
|
||||||
if etag:
|
self.headers["ETag"] = etag or generate_etag(body)
|
||||||
self.headers["ETag"] = etag
|
|
||||||
else:
|
|
||||||
self.headers["ETag"] = generate_etag(body)
|
|
||||||
|
|
||||||
if vary:
|
if vary:
|
||||||
self.headers["Vary"] = ", ".join(vary)
|
self.headers["Vary"] = ", ".join(vary)
|
||||||
|
|||||||
Reference in New Issue
Block a user