From 1314b02addbba942cc9867aef1f162a0cbd0f139 Mon Sep 17 00:00:00 2001 From: Danial Keimasi Date: Mon, 24 Jun 2024 14:19:53 +0330 Subject: [PATCH] Send Set-Cookie header from nextjs response to user and bump version 3.1.0 --- django_nextjs/__init__.py | 2 +- django_nextjs/proxy.py | 12 +++++++----- django_nextjs/render.py | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/django_nextjs/__init__.py b/django_nextjs/__init__.py index 528787c..f5f41e5 100644 --- a/django_nextjs/__init__.py +++ b/django_nextjs/__init__.py @@ -1 +1 @@ -__version__ = "3.0.0" +__version__ = "3.1.0" diff --git a/django_nextjs/proxy.py b/django_nextjs/proxy.py index 2d04e3a..353e638 100644 --- a/django_nextjs/proxy.py +++ b/django_nextjs/proxy.py @@ -30,11 +30,13 @@ async def handle(self, body): headers = {k.decode(): v.decode() for k, v in self.scope["headers"]} async with aiohttp.ClientSession(headers=headers) as session: async with session.get(url) as response: - await self.send_headers( - headers=[ - (b"Content-Type", response.headers["content-type"].encode()), - ] - ) + nextjs_response_headers = [ + (name.encode(), value.encode()) + for name, value in response.headers.items() + if name.lower() in ["content-type", "set-cookie"] + ] + + await self.send_headers(headers=nextjs_response_headers) async for data in response.content.iter_any(): await self.send_body(data, more_body=True) await self.send_body(b"", more_body=False) diff --git a/django_nextjs/render.py b/django_nextjs/render.py index f902e63..1738f80 100644 --- a/django_nextjs/render.py +++ b/django_nextjs/render.py @@ -82,6 +82,7 @@ def _get_nextjs_response_headers(headers: MultiMapping[str]) -> Dict: "Location", "Vary", "Content-Type", + "Set-Cookie", ], )