X-Forwarded-Prefix

47 views
Skip to first unread message

Marc Perrin

unread,
Jan 24, 2023, 5:48:17 PM1/24/23
to Django developers (Contributions to Django itself)
Hi,
I've been looking at the current support for X-Forwarded headers (cf. https://code.djangoproject.com/ticket/30729 or https://code.djangoproject.com/ticket/31354 for example).
Is there any plan to deal with X-Forwarded-Prefix? Or is that header not std enough?
If not, I'm not sure what would be the best / usual way for a user to customize HttpRequest  (get_raw_uri, build_absolute_uri) to deal with it.
Thanks,
Marc

Adam Johnson

unread,
Jan 25, 2023, 5:37:48 PM1/25/23
to django-d...@googlegroups.com
In a brief search, I could not find any docs for X-Forwarded-Prefix.


To customize those functions, you could use a middleware to modify requests to wrap them:

class ExampleMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        request.get_raw_uri = wrap_get_raw_uri(request.get_raw_uri)
        # ...
        return self.get_response(request)
       
def wrap_get_raw_uri(func):
    def wrapper(*args, **kwargs):
        value = func(*args, **kwargs)
        # change value appropriately
        return value
    return wrapper

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/541333bb-9238-46ae-bea4-cbe28d3dce42n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages