Changes between Initial Version and Version 3 of Ticket #35971
- Timestamp:
- Dec 4, 2024, 8:56:39 AM (3 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #35971
- Property Type Uncategorized → New feature
- Property Version dev → 5.0
-
Ticket #35971 – Description
initial v3 7 7 It would be convenient to move that logic into a separate method that could be overridden. For example: 8 8 {{{ 9 get_username(self ):10 return request.META[ self.header]9 get_username(self, header_name): 10 return request.META[header_name] 11 11 }}} 12 12 13 Specific use case: the proxy I have in front of Django always sets two specific headers (say "X-Username" and "X-Authenticated"). The value of "X-Username" is only valid if "X-Authenticated" is "true", otherwise it should be ignored (typically it ends up being a single space character). I use PersistentRemoteMiddleware to use X-Username but the only way I found to ignore it when X-Authenticated is not true is to override __call__ / __acall__ or clean_username. Both seemrather fragile while a small change to RemoteUserMiddleware would make for a much more robust, flexible and maintainable solution.13 Specific use case: the proxy I have in front of Django always sets two specific headers (say "X-Username" and "X-Authenticated"). The value of "X-Username" is only valid if "X-Authenticated" is "true", otherwise it should be ignored (typically it ends up being a single space character). I use PersistentRemoteMiddleware to use X-Username but the only way I found to ignore it when X-Authenticated is not true is to override __call__ / __acall__ , which seems rather fragile while a small change to RemoteUserMiddleware would make for a much more robust, flexible and maintainable solution. 14 14 15 15 With the proposed change, in my child class I could just say 16 16 {{{ 17 def get_username(self ):17 def get_username(self, header_name): 18 18 if request.META["X-Authenticated"].lower() != "true": 19 19 raise KeyError 20 else: 21 return request.META[self.header] 20 return request.META[header_name] 22 21 }}} 23 22 24 23 I am happy to propose a patch if we can agree this change is desirable. 24 25 The analysis above is for the latest version on github. I have marked this feature request as 5.0 because that's the version I currently use and backporting the proposed change seems easy enough.