-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from starlette.middleware.base import BaseHTTPMiddleware
class SampleMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next):
_ = await request.form()
return await call_next(request)
app = Starlette()
@app.route('/test', methods=['POST'])
async def test(request):
_ = await request.form() # blocked, because middleware already consumed request body
return PlainTextResponse('Hello, world!')
app.add_middleware(SampleMiddleware)
$ uvicorn test:app --reload
$ curl -d "a=1" http://127.0.0.1:8000/test
# request is blocked
samuelcolvin, pfrayer, olirice, ZebraCat, four43 and 13 more
Metadata
Metadata
Assignees
Labels
No labels