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
|
||||
from fastapi import Request, Response
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from comet.core.models import settings
|
||||
|
||||
@@ -116,7 +115,7 @@ def check_etag_match(request: Request, etag: str):
|
||||
return False
|
||||
|
||||
|
||||
class CachedJSONResponse(JSONResponse):
|
||||
class CachedJSONResponse(Response):
|
||||
def __init__(
|
||||
self,
|
||||
content: Any,
|
||||
@@ -127,18 +126,17 @@ class CachedJSONResponse(JSONResponse):
|
||||
**kwargs,
|
||||
):
|
||||
body = orjson.dumps(content)
|
||||
|
||||
super().__init__(content=content, status_code=status_code, **kwargs)
|
||||
|
||||
self.body = body
|
||||
super().__init__(
|
||||
content=body,
|
||||
status_code=status_code,
|
||||
media_type="application/json",
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
if cache_control:
|
||||
self.headers["Cache-Control"] = cache_control.build()
|
||||
|
||||
if etag:
|
||||
self.headers["ETag"] = etag
|
||||
else:
|
||||
self.headers["ETag"] = generate_etag(body)
|
||||
self.headers["ETag"] = etag or generate_etag(body)
|
||||
|
||||
if vary:
|
||||
self.headers["Vary"] = ", ".join(vary)
|
||||
|
||||
Reference in New Issue
Block a user