From d44f26a476f201c37d99585372ab4c2588d910d4 Mon Sep 17 00:00:00 2001 From: Lizards Date: Thu, 19 Oct 2023 17:00:43 -0400 Subject: [PATCH] Include client's User-Agent header in requests proxied through NextJSProxyView --- django_nextjs/proxy.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/django_nextjs/proxy.py b/django_nextjs/proxy.py index 353e638..92e18d5 100644 --- a/django_nextjs/proxy.py +++ b/django_nextjs/proxy.py @@ -91,10 +91,12 @@ def dispatch(self, request, *args, **kwargs): def get(self, request): url = NEXTJS_SERVER_URL + request.path + "?" + request.GET.urlencode() + headers = {} + for header in ["Cookie", "User-Agent"]: + if header in request.headers: + headers[header] = request.headers[header] - urllib_response = urllib.request.urlopen( - urllib.request.Request(url, headers={"Cookie": request.headers.get("Cookie")}) - ) + urllib_response = urllib.request.urlopen(urllib.request.Request(url, headers=headers)) return http.StreamingHttpResponse( self._iter_content(urllib_response), headers={"Content-Type": urllib_response.headers.get("Content-Type")}