Skip to content

Commit

Permalink
Cast int cookie dict max_age
Browse files Browse the repository at this point in the history
  • Loading branch information
andruten committed Feb 8, 2024
1 parent e7ad0c2 commit 4884fee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions revproxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,16 @@ def cookie_from_string(cookie_string, strict_cookies=False):
# function docstring
continue
elif attr == 'max-age':
# The cookie uses 'max-age' but django's
# set_cookie uses 'max_age'
cookie_dict['max_age'] = unquote(value)
# The cookie uses 'max-age' but django's set_cookie uses 'max_age'
try:
# Cast to Integer as Django's set_cookie() expects max_age as int
cookie_dict['max_age'] = int(unquote(value))
except ValueError:
logger.warning(
'Invalid max_age attribute value in cookie: `%s`',
cookie_string,
)
cookie_dict['max_age'] = unquote(value)
else:
cookie_dict[attr] = unquote(value)
else:
Expand Down

0 comments on commit 4884fee

Please sign in to comment.