Changes between Initial Version and Version 3 of Ticket #35971


Ignore:
Timestamp:
Dec 4, 2024, 8:56:39 AM (3 months ago)
Author:
Adrien Kunysz
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35971

    • Property Type UncategorizedNew feature
    • Property Version dev5.0
  • Ticket #35971 – Description

    initial v3  
    77It would be convenient to move that logic into a separate method that could be overridden. For example:
    88{{{
    9 get_username(self):
    10     return request.META[self.header]   
     9get_username(self, header_name):
     10    return request.META[header_name]   
    1111}}}
    1212
    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 seem rather fragile while a small change to RemoteUserMiddleware would make for a much more robust, flexible and maintainable solution.
     13Specific 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.
    1414
    1515With the proposed change, in my child class I could just say
    1616{{{
    17 def get_username(self):
     17def get_username(self, header_name):
    1818    if request.META["X-Authenticated"].lower() != "true":
    1919        raise KeyError
    20     else:
    21         return request.META[self.header]
     20    return request.META[header_name]
    2221}}}
    2322
    2423I am happy to propose a patch if we can agree this change is desirable.
     24
     25The 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.
Back to Top