1
This commit is contained in:
@@ -3,7 +3,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||||
from fastapi import Request, Response
|
from fastapi import HTTPException, Request, Response
|
||||||
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
|
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
|
||||||
|
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
@@ -98,6 +98,9 @@ class RequestEncryptMiddleware(BaseHTTPMiddleware):
|
|||||||
status_code=response.status_code,
|
status_code=response.status_code,
|
||||||
headers={"X-Encrypted": "true", "Content-Type": "application/json"},
|
headers={"X-Encrypted": "true", "Content-Type": "application/json"},
|
||||||
)
|
)
|
||||||
|
except HTTPException:
|
||||||
|
# 让 HTTPException(如 409 订单占用)正常传播,不被加密中间件拦截
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Request decryption failed")
|
logger.exception("Request decryption failed")
|
||||||
return Response(
|
return Response(
|
||||||
|
|||||||
Reference in New Issue
Block a user