Files

20 lines
546 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from fastapi import Request,Response
import time
black_list = ['192.168.1.40','192.168.1.94'] # '127.0.0.1','192.168.1.26‘
# @app.middleware("http",)
async def black(req:Request, next):
if req.client.host in black_list:
return Response("you are limited to access!")
res = await next(req)
# print('exite http',req.client.host)
return res
# @app.middleware("https")
async def time_(req:Request, next):
print('enter https',time.time())
res = await next(req)
print('exite https',time.time())
return res