You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a similar issue as what was raised in #5 and was thinking of adding a LOCKDOWN_HOST_EXCEPTIONS. As the idea was previously rejected, I wanted to try to subclass the LockdownMiddleware and add my own logic before main one, but found that this was a bit more difficult that I thought.
Basically, I was thinking of adding my logic after the initial checks, and before further checks are done:
I think that could be achieved by calling a method on the middleware class which by default wouldn't do anything, but which would enable user to hook into their custom logic by returning something specific.
Changed middleware:
classLockdownMiddleware(object):
...
defprocess_request(self, request):
...
# Don't lock down if django-lockdown is disabled altogether.ifgetattr(settings, 'LOCKDOWN_ENABLED', True) isFalse:
returnNone# NEW: Call hookifself.is_request_excluded(request):
returnNone
...
defis_request_excluded(self, request): # New method"""Hook for users to implement a custom logic to exclude the request."""returnFalse
Example implementation in user-land:
fromlockdown.middlewareimportLockdownMiddlewareasBaseLockdownMiddlewareclassLockdownMiddleware(BaseLockdownMiddleware):
defis_request_excluded(self, request, response):
returnrequest.get_host() in ["api.mysite.com"]
What do you think?
The text was updated successfully, but these errors were encountered:
I have a similar issue as what was raised in #5 and was thinking of adding a
LOCKDOWN_HOST_EXCEPTIONS
. As the idea was previously rejected, I wanted to try to subclass theLockdownMiddleware
and add my own logic before main one, but found that this was a bit more difficult that I thought.Basically, I was thinking of adding my logic after the initial checks, and before further checks are done:
django-lockdown/lockdown/middleware.py
Lines 92 to 94 in be8224e
I think that could be achieved by calling a method on the middleware class which by default wouldn't do anything, but which would enable user to hook into their custom logic by returning something specific.
Changed middleware:
Example implementation in user-land:
What do you think?
The text was updated successfully, but these errors were encountered: