fastapi-sessions
fastapi-sessions copied to clipboard
fix samesite enum bug
- add
__str__
to override the__str__
of the enum class; fixes #16
the issue:
the sameSiteEnum
is getting serialized wrongly in the set-cookie header. that is because Enum
class is overriding the __str__
of the string class. https://github.com/python/cpython/blob/ca3e611b1f620eabb657ef08a95d5f5f554ea773/Lib/enum.py#L1173-L1175
And despite that response.set_cookie
is doing a great work to check the validity of the cookie parameter but calling the .lower()
will get the original str but using the variable directly in line#135 is calling the __str__
method of the enum class hence it bypasses this check.
https://github.com/encode/starlette/blob/master/starlette/responses.py#L129-L136.
solution:
I added the a __str__
to get the original string value as described here in the docs.
before the fix:
after the fix:
Signed-off-by: mahmednabil109 [email protected]
@jordanisaacs can you pls review?
Same issue here, any chance to merge this?