fix(http): 保留业务响应缓存头

This commit is contained in:
yml
2026-11-23 16:56:18 +08:00
parent b30b16294f
commit d5422b0ecd
2 changed files with 65 additions and 8 deletions
+10 -8
View File
@@ -118,19 +118,21 @@ class SecurityHeadersMiddleware:
await self.app(scope, receive, send)
return
path = str(scope.get("path") or "")
is_asset = path.startswith("/assets/")
async def send_wrapper(message: Any):
if message["type"] == "http.response.start":
replaced_headers = {
b"x-content-type-options",
b"x-frame-options",
b"referrer-policy",
}
if is_asset:
replaced_headers.add(b"cache-control")
headers = [
(key, value)
for key, value in message.get("headers", [])
if key
not in {
b"x-content-type-options",
b"x-frame-options",
b"referrer-policy",
b"cache-control",
}
if key not in replaced_headers
]
headers.extend(
[
@@ -142,7 +144,7 @@ class SecurityHeadersMiddleware:
),
]
)
if path.startswith("/assets/"):
if is_asset:
headers.append(
(
b"cache-control",