Created
July 1, 2018 08:42
-
-
Save Ruhshan/d2c0ce1927064320bd7122f0fe9e6e0d 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
def OriginRestrictor(get_response): | |
def middleware(request): | |
forbid = False | |
for method in ['CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']: | |
if request.method==method and method in method_remote.keys(): | |
allowed_origin = method_remote[method] | |
request_origin = request.META['REMOTE_ADDR'] | |
if request_origin not in allowed_origin: | |
forbid=True | |
break | |
if forbid==True: | |
return HttpResponseForbidden() | |
response = get_response(request) | |
return response | |
return middleware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment