Last active
October 22, 2022 02:27
-
-
Save vndee/7f3ea6f385f391eaac8d57f3d8abfb76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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