Skip to content

Instantly share code, notes, and snippets.

@Ruhshan
Created July 1, 2018 08:42
Show Gist options
  • Save Ruhshan/d2c0ce1927064320bd7122f0fe9e6e0d to your computer and use it in GitHub Desktop.
Save Ruhshan/d2c0ce1927064320bd7122f0fe9e6e0d to your computer and use it in GitHub Desktop.
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