generated from jCloud/repository-template
Bug fix: HTTPException should not be used in a middleware, so use JSONResponse instead
This commit is contained in:
@@ -16,6 +16,7 @@ import hmac
|
||||
import hashlib
|
||||
from fastapi import Request, HTTPException
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
__all__ = [
|
||||
'GiteaSignatureMiddleware'
|
||||
@@ -45,7 +46,10 @@ class GiteaSignatureMiddleware(BaseHTTPMiddleware):
|
||||
signature = request.headers.get('X-Gitea-Signature')
|
||||
|
||||
if not signature:
|
||||
raise HTTPException(status_code = 401, detail = 'Missing signature')
|
||||
return JSONResponse(
|
||||
status_code = 401,
|
||||
content = {'detail': 'Invalid signature'}
|
||||
)
|
||||
|
||||
body = await request.body()
|
||||
|
||||
@@ -57,6 +61,9 @@ class GiteaSignatureMiddleware(BaseHTTPMiddleware):
|
||||
).hexdigest()}',
|
||||
signature
|
||||
):
|
||||
raise HTTPException(status_code = 401, detail = 'Invalid signature')
|
||||
|
||||
return JSONResponse(
|
||||
status_code = 401,
|
||||
content = {'detail': 'Invalid signature'}
|
||||
)
|
||||
|
||||
return await call_next(request)
|
||||
Reference in New Issue
Block a user