Skip to content

Commit

Permalink
Merge pull request #103 from PrieJos/bugfix-97
Browse files Browse the repository at this point in the history
Fix case sensitiveness in HTTPHeaderDict (#97)
  • Loading branch information
aliev authored Oct 12, 2024
2 parents ef63132 + 076e13e commit 1971573
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions aioauth/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from collections import UserDict
from typing import Any


class HTTPHeaderDict(UserDict):
Expand All @@ -33,8 +34,24 @@ class HTTPHeaderDict(UserDict):
d['hElLo'] == 'world' # >>> True
"""

def __init__(self, dict=None, **kwargs):
"""Object initialization."""
super().__init__(dict, **kwargs)
self.data = {k.lower(): v for k, v in self.data.items()}

def __setitem__(self, key: str, value: str):
super().__setitem__(key.lower(), value)

def __getitem__(self, key: str):
return super().__getitem__(key.lower())

def __delitem__(self, key: str):
"""Item deletion."""
return super().__delitem__(key.lower())

def get(self, key: str, default: Any = None):
"""Case-insentive get."""
try:
return self[key]
except KeyError:
return default

0 comments on commit 1971573

Please sign in to comment.