Skip to content

Commit

Permalink
Merge pull request #33 from Lizards/proxy-include-user-agent
Browse files Browse the repository at this point in the history
Include client's User-Agent header in requests to NextJS server from NextJSProxyView
  • Loading branch information
danialkeimasi authored Jul 7, 2024
2 parents 1314b02 + d44f26a commit aab153a
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 aab153a

Please sign in to comment.