Skip to content

Instantly share code, notes, and snippets.

@vndee
Last active October 22, 2022 02:27
Show Gist options
  • Save vndee/7f3ea6f385f391eaac8d57f3d8abfb76 to your computer and use it in GitHub Desktop.
Save vndee/7f3ea6f385f391eaac8d57f3d8abfb76 to your computer and use it in GitHub Desktop.
@app.middleware("http")
async def check_token(request: Request, _next) -> Response:
if request.headers["apiKey"] != "this_is_my_key":
return JSONResponse({"message": "Your key is mismatched"})
start_time = time.time()
response: Response = await _next(request)
response.headers["X-Process-Time"] = str(time.time() - start_time)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment