Skip to content

Commit b0116b1

Browse files
committed
minor improvement to parse_cookies
1 parent ee85d0a commit b0116b1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

osbot_utils/utils/Http.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def http_request(url, data=None, headers=None, method='GET', encoding ='utf-8',
8080
return result
8181

8282

83-
def parse_cookies(cookie_header):
83+
def parse_cookies(cookie_header, include_empty=True):
8484
cookie = SimpleCookie()
8585
cookie.load(cookie_header)
8686
parsed_cookies = {}
@@ -90,7 +90,8 @@ def parse_cookies(cookie_header):
9090
if attr.lower() in ["secure", "httponly"]:
9191
cookie_attrs[attr] = (value == True)
9292
else:
93-
cookie_attrs[attr] = value.strip(', ') # we need to strip for the cases when there are multiple cookies split by , (as seen in FastAPI Test Client)
93+
if value or include_empty:
94+
cookie_attrs[attr] = value.strip(', ') # we need to strip for the cases when there are multiple cookies split by , (as seen in FastAPI Test Client)
9495
parsed_cookies[key] = cookie_attrs
9596

9697
return parsed_cookies

0 commit comments

Comments
 (0)