Skip to content

Commit 21af406

Browse files
committed
chore(cookies): format date
1 parent db7c9d9 commit 21af406

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

aws_lambda_powertools/shared/cookies.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class SameSite(Enum):
1111
NONE_MODE = "None"
1212

1313

14+
def _getdate(timestamp: datetime) -> str:
15+
return timestamp.strftime("%a, %d %b %Y %H:%M:%S GMT")
16+
17+
1418
class Cookie:
1519
def __init__(
1620
self,
@@ -38,21 +42,16 @@ def __init__(
3842

3943
def __str__(self) -> str:
4044
payload = StringIO()
41-
payload.write(f"{self.name}=")
42-
43-
# Maintenance(rf): the value needs to be sanitized
44-
payload.write(self.value)
45+
payload.write(f"{self.name}={self.value}")
4546

4647
if self.path and len(self.path) > 0:
47-
# Maintenance(rf): the value of path needs to be sanitized
4848
payload.write(f"; Path={self.path}")
4949

5050
if self.domain and len(self.domain) > 0:
5151
payload.write(f"; Domain={self.domain}")
5252

5353
if self.expires:
54-
# Maintenance(rf) this format is wrong
55-
payload.write(f"; Expires={self.expires.strftime('YYYY-MM-dd')}")
54+
payload.write(f"; Expires={_getdate(self.expires)}")
5655

5756
if self.max_age:
5857
if self.max_age > 0:
@@ -71,7 +70,6 @@ def __str__(self) -> str:
7170

7271
if self.custom_attributes:
7372
for attr in self.custom_attributes:
74-
# Maintenance(rf): the value needs to be sanitized
7573
payload.write(f"; {attr}")
7674

7775
return payload.getvalue()

0 commit comments

Comments
 (0)