Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Fixed encrypted cookies engine mistake #233

Open
wants to merge 3 commits into
base: v0.1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vibora/request/request.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ cdef class Request:
:return:
"""
if not self._session:
self._session = await self.app.session_engine.load(self.cookies)
self._session = await self.app.session_engine.load(self)
return self._session

async def json(self, loads=None, strict: bool=False) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion vibora/sessions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self, cookie_name: str = None):
async def load(self, request):
raise NotImplementedError

async def save(self, request, response):
async def save(self, pending_session, response):
raise NotImplementedError

async def clean_up(self):
Expand Down
4 changes: 2 additions & 2 deletions vibora/sessions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ async def load(self, request) -> Session:
return Session(pending_flush=True)
return Session()

async def save(self, request, response) -> None:
async def save(self, pending_session, response) -> None:
"""
Inject headers in the response object so the user will receive
an encrypted cookie with session values.
:param request: current Request object
:param response: current Response object where headers will be inject.
:return:
"""
value = self.cipher.encrypt(request.session.dumps().encode())
value = self.cipher.encrypt(pending_session.dumps().encode())
cookie = f"{self.cookie_name}={value.decode()}; SameSite=Lax"
response.headers["Set-Cookie"] = cookie