Skip to content

Commit a36fb64

Browse files
made session fetching more clear, fixed a bug with lcdict
1 parent c3d63c7 commit a36fb64

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/nussschale/handler.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,15 @@ def do_heartbeat() -> None:
122122
exit(1)
123123

124124
def fetch_session(self) -> Tuple[Session, bool]:
125-
# Find the session cookie (if any)
126-
cookie_hdr = ""
127-
try:
128-
cookie_hdr = self._str_headers["cookie"]
129-
except KeyError:
130-
pass
131-
cookie = SimpleCookie(cookie_hdr) # type: ignore
132-
133-
# Extract the session ID
125+
# Find the session cookie (if any) and extract the ID
134126
sid = None # type: Optional[str]
135-
try:
136-
sid = cookie["session"].value
137-
except KeyError:
138-
pass
127+
if "cookie" in self._str_headers:
128+
cookie = SimpleCookie(self._str_headers["cookie"]) # type: ignore
129+
if "session" in cookie:
130+
sid = cookie["session"].value
131+
if sid == "":
132+
nlog().log("Empty session ID, reassigning...")
133+
sid = None
139134

140135
# Fetch (or create) the session
141136
session = Session.get_session(self.client_address[0], sid)

src/nussschale/util/lcdict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __contains__(self, key: Any) -> bool:
7070
Whether the key is present.
7171
"""
7272
assert isinstance(key, str), "key is no string"
73-
return key in self._backing
73+
return key.lower() in self._backing
7474

7575
def __delitem__(self, key: str) -> None:
7676
"""Deletes an item.

0 commit comments

Comments
 (0)