Skip to content

another fix for #294 #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions aiohttp_session/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, redis_pool, *, cookie_name="AIOHTTP_SESSION",
domain=None, max_age=None, path='/',
secure=None, httponly=True,
key_factory=lambda: uuid.uuid4().hex,
encoder=json.dumps, decoder=json.loads):
encoder=json.dumps, decoder=json.loads, str_decode=True):
super().__init__(cookie_name=cookie_name, domain=domain,
max_age=max_age, path=path, secure=secure,
httponly=httponly,
Expand All @@ -38,6 +38,7 @@ def __init__(self, redis_pool, *, cookie_name="AIOHTTP_SESSION",
raise TypeError("Expexted aioredis.commands.Redis got {}".format(
type(redis_pool)))
self._redis = redis_pool
self.str_decode = str_decode

async def load_session(self, request):
cookie = self.load_cookie(request)
Expand All @@ -50,7 +51,8 @@ async def load_session(self, request):
if data is None:
return Session(None, data=None,
new=True, max_age=self.max_age)
data = data.decode('utf-8')
if self.str_decode:
data = data.decode('utf-8')
try:
data = self._decoder(data)
except ValueError:
Expand Down