Skip to content

Commit

Permalink
Include client's User-Agent header in requests proxied through NextJS…
Browse files Browse the repository at this point in the history
…ProxyView
  • Loading branch information
Lizards committed Jul 1, 2024
1 parent 1314b02 commit d44f26a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions django_nextjs/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down

0 comments on commit d44f26a

Please sign in to comment.